0

I send a simple text message to an MQ Queue (MQ 7.0.1): "abc"

  • Using spring JMS the total length of the message is: 291 spring jms total length

spring jms properties with names

  • But putting the same message in the queue using IBM MQ libraries the total length of the message is: 3 ibm mq libraries total length

How can I get total data length 3 with JMS?

Spring JMS code:

@EnableJms
public class JMSTestController {
...

@Autowired
private JmsTemplate jmsTemplate;

@Autowired
JmsMessagingTemplate jmsMessagingTemplate;

...

public String send() throws JMSException{
    jmsTemplate.setReceiveTimeout(10000);
    jmsMessagingTemplate.setJmsTemplate(jmsTemplate);
    
    Session session = jmsMessagingTemplate.getConnectionFactory().createConnection()
            .createSession(false, Session.AUTO_ACKNOWLEDGE);
    
    Queue entryQueue = session.createQueue("hereQueueName");
    Queue replyQueue = session.createQueue("hereReplyQueueName");


    TextMessage message = session.createTextMessage("abc");
    message.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
    message.setJMSDestination(entryQueue);
    message.setIntProperty(WMQConstants.JMS_IBM_CHARACTER_SET, 819);
    message.setIntProperty(WMQConstants.JMS_IBM_ENCODING, 273);

    jmsMessagingTemplate.convertAndSend(entryQueue, message);

    String messageId = message.getJMSMessageID();
    ...    

}

Native code:

MQQueueManager qm = createQueueManager(queueManager, host, port,
            channel, username, password, connectionType);
MQQueue m_receiver = null;

MQMessage msg = new MQMessage();
msg.format = MQC.MQFMT_STRING;
msg.expiry = timeout / 1000;
msg.replyToQueueName = qReceiver;
msg.replyToQueueManagerName = queueManager;
msg.write("abc".getBytes());
MQPutMessageOptions pmo = new MQPutMessageOptions();
try {
    qm.put(qSender, msg, pmo);
} catch (MQException e) {
    MQTalkerException ex = new MQTalkerException(
            "An error happened sending a message", e);
    logger.error(ex);
    throw ex;
}

Solution

Following JoshMc's comment I made the following modification and reached the expected result:

Check out these answers, you want to set targetClient to MQ to remove those properties. There are many ways to accomplish this, changing your CreateQueue to use a URI is probably the easiest. JMS transport v/s MQ transport

That is, modify the creation of the queue using the URI instead of just its name.

Queue entryQueue = session.createQueue("queue:///QUEUE_NAME?targetClient=1");
  • 1
    In your second screen shot you have a section titled "propiedades con nombres" ("properties with names") which will likely account for the difference in length. Please can you also show us a screen shot of that section of the message and from there we should be able to explain the difference. I am surprised that it is the native one that has properties and the JMS one that doesn't so also double check you have them the right way around. – Morag Hughson May 29 '21 at 00:10
  • Morag, thank you for your reply. It is true, I mistakenly exchange the screenshots: with jms there is a total length of 291. I attached the "properties with names" screenshot. – Fernando Palena May 29 '21 at 14:06
  • 2
    Check out these answers, you want to set targetClient to MQ to remove those properties. There are many ways to accomplish this, changing your CreateQueue to use a URI is probably the easiest. https://stackoverflow.com/questions/3385576/jms-transport-v-s-mq-transport – JoshMc May 29 '21 at 15:09
  • @JoshMc, just as you indicated, changing the createQueue stopped sending the "properties with names". ¡Thanks! – Fernando Palena May 31 '21 at 13:15
  • 1
    The extra 288 bytes is the MQRFH2 header. By setting targetClient to MQ, the MQ Client library will not put the MQRFH2 header on the message. If you are sending the message to a non-JMS application then setting targetClient to MQ is the correct approach. – Roger May 31 '21 at 17:32

2 Answers2

0

I reached the solution by following JoshMc's comment. That is, modify the creation of the queue using the URI instead of just its name.

Queue entryQueue = session.createQueue("queue:///QUEUE_NAME?targetClient=1");

This removes the MQRFH2 header (the extra bytes I didn't know where they came from) and with that the message has a total length of 3 bytes.

-1

Spring is counting the bytes of the message body (aka data)

IBM MQ native is counting the bytes of the message headers plus body

In your screenshot, the field directly above shows '3' bytes.

Longitud dataos = length of body = 3

Longitud total = length of headers + body = 291

Matt Pavlovich
  • 4,087
  • 1
  • 9
  • 17