How to set message Id for IBM MQ using java program

怎甘沉沦 提交于 2019-12-24 10:55:53

问题


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);
    }
}

} I am getting below error

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

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.

due to this line


回答1:


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.

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.

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).

Further reading

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


来源:https://stackoverflow.com/questions/52889361/how-to-set-message-id-for-ibm-mq-using-java-program

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!