Skip to content
Advertisement

How can I get ByteBuffer body from WMQTextMessage.java instead of calling getText()?

I have a Spring Boot application which is listening to IBM MQ using the JMS API. The application is running in a severely memory constrained environment.

I receive a TextMessage object. I can call getText() and get the message content in String form, but this String is actually being created from a ByteBuffer which already exists in WMQTextMessage.java. Therefore, I don’t want to call getText() since creating a new String from the ByteBuffer will use more memory.

Instead I want to get the ByteBuffer directly from the WMQTextMessage.java. There is a method called public byte[] _exportBody in WMQTextMessage.java, but I can’t call this method I think.

Can someone please help me with this? Here is the simple code I have:

@JmsListener()
public void messageListener (TextMessage message) {
   String data = message.getText(); //need to avoid this and get data in byte[] to save space
}

Advertisement

Answer

If _export() is a public method on WMQTextMessage then you should be able to cast the TextMessage to WMQTextMessage and call it no problem, e.g.:

@JmsListener()
public void messageListener (TextMessage message) {
   byte[] data = ((WMQTextMessage)message)._export();
}

However, since the _export() method returns a byte[] and not a ByteBuffer then it is almost certainly copying the data from the ByteBuffer into a new byte[] and therefore would use extra heap just like calling getText().

IBM MQ is closed source as far as I can tell. If you’re decompiling the client jar in order to actually look at WMQTextMessage.java then you may be violating your software license agreement with IBM or possibly even the DMCA. It may sound silly for something so innocuous, but the laws around technology are often silly given that the folks who write them don’t usually understand the nuances of the technology in the first place. I recommend you work directly with IBM to get these specific questions answered.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement