Thursday 2 February 2017

com.ibm.msg.client.jms.DetailedIllegalStateException: JMSWMQ2007

com.ibm.msg.client.jms.DetailedIllegalStateException: JMSWMQ2007

Problem: I was trying to set expiration time for my MQ messages using Spring JMS Template.
        jmsTemplate.setExplicitQosEnabled(true);
        jmsTemplate.setTimeToLive(expiryTime); 
And for expiration report, trying to set Textmessage properties.
       textMessage.setIntProperty(JmsConstants.JMS_IBM_REPORT_EXPIRATION,  MQC.MQRO_EXPIRATION_WITH_DATA);
        textMessage.setIntProperty(JmsConstants.JMS_IBM_REPORT_PASS_MSG_ID, MQC.MQRO_PASS_MSG_ID); 
When I am trying to execute program, getting below MQ exception.

com.ibm.msg.client.jms.DetailedIllegalStateException: JMSWMQ2007,Failed to send a message to destination . JMS attempted to perform an MQPUT or MQPUT1; however WebSphere MQ reported an error. Use the linked exception to determine the cause of this error.

com.ibm.msg.client.jms.DetailedIllegalStateException: JMSWMQ2007

  

 

 

Solution:  When we set property for expiration report, need to also set ReplyToQueue and ReplyToQueueManager. If any message got expired than Expiration report will be sent back to mentioned ReplyToQueueManager and ReplyToQueue by MQ Queue Manager.

private void setJMSProperty(TextMessage textMessage, String ReplyToQueueMgr, String ReplyToQueue) throws JMSException {
        MQQueue replyToQ = new MQQueue(ReplyToQueueMgr, ReplyToQueue);
        Destination replyTo = (Destination) replyToQ;
        textMessage.setJMSReplyTo(replyTo);
        textMessage.setIntProperty(JmsConstants.JMS_IBM_REPORT_EXPIRATION, MQC.MQRO_EXPIRATION_WITH_DATA);
        textMessage.setIntProperty(JmsConstants.JMS_IBM_REPORT_PASS_MSG_ID, MQC.MQRO_PASS_MSG_ID);
    }

 

How to set MQ instance for installation   

If your machine installed with number of MQ instance, than by using below command we can set instance.

  • Go to bin folder of MQ installation path in command prompt, in my system it is 

    C:\Program Files (x86)\IBM\WebSphere MQ\bin

    Execute the command "setmqinst -n Installation(n) -i" where n is 1,2,3.... I wanted to set in my machine as installation1 so command will be.

     C:\Program Files (x86)\IBM\WebSphere MQ\bin\setmqinst -n Installation1 -i


Important summary:  

1. How to set IBM MQ expiration time

jmsTemplate.setExplicitQosEnabled(true);
jmsTemplate.setTimeToLive(expiryTime);

2. How to set IBM MQ expiration report

  textMessage.setIntProperty(JmsConstants.JMS_IBM_REPORT_EXPIRATION,  MQC.MQRO_EXPIRATION_WITH_DATA);
        textMessage.setIntProperty(JmsConstants.JMS_IBM_REPORT_PASS_MSG_ID, MQC.MQRO_PASS_MSG_ID); 

3. How to set IBM MQ ReplyToQueue and ReplyToQueueManager

private void setJMSProperty(TextMessage textMessage, String ReplyToQueueMgr, String ReplyToQueue) throws JMSException {
        MQQueue replyToQ = new MQQueue(ReplyToQueueMgr, ReplyToQueue);
        Destination replyTo = (Destination) replyToQ;
        textMessage.setJMSReplyTo(replyTo);
        textMessage.setIntProperty(JmsConstants.JMS_IBM_REPORT_EXPIRATION, MQC.MQRO_EXPIRATION_WITH_DATA);
        textMessage.setIntProperty(JmsConstants.JMS_IBM_REPORT_PASS_MSG_ID, MQC.MQRO_PASS_MSG_ID);
    }

No comments:

Post a Comment