1
votes

I tested a standalone JMS client passing a TextMessage to a queue on IBM MQ, and I got the below message id with error:

ID:414d51204243573032413154202020205bc6bd3e25423865

java.lang.RuntimeException: no text message

  1. I sent a TextMessage with This is for Test, but why didn't I receive a TextMessage? There were no other messages in the queue before this code ran.
  2. In case text message success how to read the message Id (send request MessageID and reply message Id) in readable format in Java. Is any thing I need to change in the below code.
TextMessage textMessage = queueSession.createTextMessage("This is for Test");
textMessage.setJMSReplyTo(queue);
textMessage.setJMSType("mcd://xmlns");//message type
textMessage.setJMSExpiration(2*1000);//message expiration
textMessage.setJMSDeliveryMode(DeliveryMode.PERSISTENT); 
queueSender = queueSession.createSender(queueSession.createQueue(outputQName));
queueSender.setTimeToLive(2*1000);
queueSender.send(textMessage);

String jmsCorrelationID = " JMSCorrelationID = '" + textMessage.getJMSMessageID() + "'";
while (true) {                        
    Message message = queueReceiver.receive(60*1000);
    if (! (message instanceof TextMessage))
        throw new RuntimeException("no text message");
    TextMessage tm = (TextMessage) message;
    System.out.println("Message:"+tm.getText());  
}
3
Which broker service?YetAnotherBot
Receive call has returned. Meaning it has found a message. Are you sure there are no other messages in the queue before you sent a message?Shashi
For messageid see this link: stackoverflow.com/questions/45729239/…Shashi
IBM MQ broker serviceMaxtech
Yes no other messages in the queue before you sent a messageMaxtech

3 Answers

0
votes

Could this simply be that your message is expiring from the queue?

I see you set the message expiry to 2 seconds. Many replying applications will copy the remaining expiry value to the reply message. So if the app that reads the request and sends you the reply does not read your request within 2 seconds from the time it was sent, or if it does and replies with the remaining expiry and the reply does not make it back to be consumed by you, it would disappear from the queue.

Try increasing the expiry time to a higher value.


Also note you are setting the same expiry value via two different methods, one is meant to be a default for all messages sent by the producer and the other is a per message setting.

This sets a default expiry on all messages sent by the producer:

queueSender.setTimeToLive(2*1000);

This sets the expiry on the specific message you are sending and would override the queueSender.setTimeToLive, so you only need one of these lines.

textMessage.setJMSExpiration(2*1000);//message expiration
0
votes

In your request-reply use-case the kind of message the requesting client sends has no direct bearing on the kind of message it will receive. The kind of message the requesting client receives depends on what the responding client sends.

As for getting the message ID as a String from the IBM MQ implementation you can refer to this answer.

0
votes

Is your session transactional?
If yes then your message is not "visible" on the queue until the transaction is "commit" and you never commit...
I'm curious to know what is the content ofmessage when you test its class..is it null?
Does the receivereturn immediately or only after the timeout expired (in your case 60*1000ms)?
Denis