如何使用Java程序为IBM MQ设置消息ID [英] How to set message Id for IBM MQ using java program

查看:1542
本文介绍了如何使用Java程序为IBM MQ设置消息ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够为IBM mq设置相关性ID,但是无法为MQ覆盖我正在设置的消息ID的消息设置消息ID.如何在下面设置此消息ID是我正在尝试的代码,请帮助我在完成这项任务.代码中有什么我需要做的吗?

I am able to set correlation id for IBM mq but unable to set message id for the message the message id I am setting is being overridden by the MQ how to set this message id below one is the code I am trying please help me on this task. Is there any thing I need do in the code???

 public static void main(String args[]) 
    {

    try{
       MQQueueConnectionFactory cf = new MQQueueConnectionFactory();
          cf.setHostName("xxx");
          cf.setPort(4444);
          cf.setTransportType(1);
          cf.setQueueManager("xxxx");
          cf.setChannel("CLIENT.xyZ");

          MQQueueConnection connection = (MQQueueConnection) cf.createQueueConnection();
          MQQueueSession session = (MQQueueSession) connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

          MQQueue queue = (MQQueue) session.createQueue("WW.ESB.ENTRY.SERVICE.IN");
          queue.setBooleanProperty(WMQConstants.WMQ_MQMD_WRITE_ENABLED, true);
 queue.setIntProperty(WMQConstants.WMQ_MQMD_MESSAGE_CONTEXT, WMQConstants.WMQ_MDCTX_SET_IDENTITY_CONTEXT);
          MQQueueSender sender =  (MQQueueSender) session.createSender(queue);

          true);




          File f=new File("C:/InputPayloads/Payloads/test4.xml");
          JMSTextMessage message = (JMSTextMessage) session.createTextMessage(FileUtils.readFileToString(f)); 
          message.setStringProperty("JMS_IBM_MQMD_UserIdentifier", "avada2");


          // Hex-string 010203040506070801020304050607080102030405060708
          byte[] customMessageId = new byte[24];
          for (int i = 0; i < 24; i++) {
            customMessageId[i] = (byte) ((i % 8) + 1);
          }

           message.setObjectProperty(WMQConstants.JMS_IBM_MQMD_MSGID, customMessageId);


          message.setStringProperty("xxx", "SH_TEST04");
          message.setStringProperty("yyy", "JP");
          message.setStringProperty("zzz", "1");
          connection.start();

          System.out.println("before Sent message:\\n" + message);

          sender.send(message);
          System.out.println("Sent message:\\n" + message);

          sender.close();
          session.close();
          connection.close();
    }catch(Exception e)
    {
        System.out.println(e);
    }
}

} 我遇到错误了

com.ibm.msg.client.jms.DetailedJMSSecurityException: JMSWMQ2008: Failed to open MQ queue 'WW.zzz.xxx.yyy.zz'.

JMS尝试执行MQOPEN,但是IBM MQ报告了错误. 使用链接的异常来确定此错误的原因.检查是否正确定义了指定的队列和队列管理器.

JMS attempted to perform an MQOPEN, but IBM MQ reported an error. Use the linked exception to determine the cause of this error. Check that the specified queue and queue manager are defined correctly.

由于此行

推荐答案

JMS规范指示消息ID必须由JMS提供者设置,并且它必须是唯一的或为null,即您不能自己设置它.

The JMS Spec indicates that the message ID must be set by the JMS provider and that it must either be unique or null, i.e. you can't set it yourself.

但是,您可以使用IBM MQ特定的扩展名来自己设置消息标识,同时要记住您现在正在违反JMS规范.

However, you can use an IBM MQ specific extension to set the Message ID yourself, bearing in mind that you are now breaking the JMS Spec.

为此,您需要设置JMS_IBM_MQMD_MsgId,然后将其值复制到JMSMessageID中(即,不能直接设置它).

To do so, you need to set JMS_IBM_MQMD_MsgId, whose value is then copied into JMSMessageID (i.e. you can't set it directly).

现在您知道要设置的属性的名称,请参见

Now you know the name of the attribute to set, see this other question for more details and a code example in an answer from an IBM MQ JMS expert (@Calanais).

进一步阅读

  • JMS message object properties
  • Reading and writing the message descriptor from a WebSphere MQ classes for JMS application

这篇关于如何使用Java程序为IBM MQ设置消息ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆