以本地时间解析IBM MQ事件监视消息

问题描述 投票:1回答:1

我正在使用IBM提供的示例程序amqsevt来监视MQ事件队列并解析消息。但我注意到,默认情况下,事件创建时间以GMT时间表示。我想将它转换为系统本地时间。有没有办法实现这个目标?

**** Message #1 (120 Bytes) on Queue SYSTEM.ADMIN.CHANNEL.EVENT ****
Event Type                       : Channel Event [46]
Reason                           : Channel Stopped By User [2279]
Event created                    : 2018/09/04 20:17:39.48 GMT
events timezone ibm-mq gmt
1个回答
2
投票

可以在/opt/mqm/opt/mqm/samp/amqsevta.c上安装MQ的Linux上找到该示例的源代码。

在每条消息的MQMD(消息描述符)中,有一个PutDatePutTime字段,它总是存储在GMT中,例如每个简单的8位字符串:

  • PutDate:20180904(YYYYMMDD)
  • 生日:20173948(hmmmmms)

在示例程序中,它只是将其转换为2018/09/04 20:17:39.48的显示格式,并将GMT追加到最后,因为它知道这总是在GMT中。

  /**********************************************************/
  /* Timestamp is read from the MQMD - it is always in GMT  */
  /* regardless of local timezone. Do not want to try to    */
  /* convert it, because this machine may be a client in a  */
  /* different timezone than the server generating the      */
  /* event. So stick to GMT (or UCT if you prefer).         */
  /**********************************************************/
  sprintf(valbuf,"%4.4s/%2.2s/%2.2s %2.2s:%2.2s:%2.2s.%2.2s GMT",
     &pMsgDesc->PutDate[0],
     &pMsgDesc->PutDate[4],
     &pMsgDesc->PutDate[6],
     &pMsgDesc->PutTime[0],
     &pMsgDesc->PutTime[2],
     &pMsgDesc->PutTime[4],
     &pMsgDesc->PutTime[6]);
  printLine(offset,"Event created",valbuf);

看起来你可以使用c函数strptime将字符串解析为一个纪元时间戳,然后在你当地的时区打印。

© www.soinside.com 2019 - 2024. All rights reserved.