简体   繁体   中英

How to set message Id for IBM MQ using java program

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

The JMS Spec indicates that the message ID must be set by the JMS provider and that it must either be unique or null, ie 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 (ie 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM