MQ JMS Double Get API Calls

Tuning applications is always a good thing. 🙂

Colin Paice has reminded me of the MQ JMS default value for an MQGET buffer size is 4KB in his blog posting here. IBM’s default value of 4KB is far too low to be useful. Having such a low value causes excessive number of MQ JMS Get API calls being issued by MQ JMS applications. Most developers/programming have no clue that this happens in JMS when issuing an MQ Get API call.

By MQ JMS Get API call, I’m talking about the QueueReceiver’s receive method.
i.e.

QueueReceiver qr = session.createReceiver(q);
Message msg = qr.receive(10000);

Normally, I would post my comments on Colin’s blog but he doesn’t approve my comments, so I figured I would write something here. Note: Colin is not the only one, IBM Developer blog author’s sometimes don’t approve my comments either. What can you do!

The default maximum message length in IBM MQ is 4194304 (4MB). Unless your MQAdmin has changed the queue’s maximum message length then it will be 4MB.

I have a lot of customers who send messages with XML data. One message could be 50KB whereas the next message could be 240KB (or larger). Trying to pick the correct maximum message length is like trying to catch a falling knife. It is just something you shouldn’t do. It is far, far better to simply use whatever the queue’s maximum message length is (which is typically 4194304).

So, here is how you should invoke/start your MQ JMS application:
i.e.

java -Dcom.ibm.mq.jmqi.defaultMaxMsgSize=4194304 testpgm

Now if you are worried about JVM running out of memory or transmiting an excessive amount data over the network that won’t happen. If you set a 4MB buffer for an MQGET, MQ will only transmit the actual size of the message (i.e. 20KB or 1.5MB). And the message object created in Java will only be the size of the actual message.

Finally, for those users who have changed a queue’s maximum message length from 4MB to a larger value (maximum is 100MB), then I suggest you set your JVM parameter to be whatever your new maximum message length is, otherwise every JMS get call will actually result in 2 get calls. Because the first call will return a reason code of 2080 (MQRC_TRUNCATED_MSG_FAILED). Hence, the second get call will use a new larger buffer.

Update: Currently, the JVM environment variable ‘com.ibm.mq.jmqi.defaultMaxMsgSize’ is undocumented. Hence, the usage may change in a future release.

Regards,
Roger Lacroix
Capitalware Inc.

This entry was posted in IBM i (OS/400), IBM MQ, Java, JMS, Linux, macOS (Mac OS X), Programming, Unix, Windows, z/OS.

Comments are closed.