JAVA - jms, slow browsing on large text messages

2019-07-17 04:28发布

问题:

i have some problem to boost my jms browser. I need to browse and display ONLY header information of te messages, but when i browsing on a Q with a lot of large text\xml messages the browser run very slow, i think it's depend by the size of the messages body but i dont need the body.

QUESTION: is there a way to get only the header information from the message enumerator?

Ty.

CODE:

browser = session.createBrowser(q);
        @SuppressWarnings("unchecked")
        Enumeration msgs = browser.getEnumeration();
        if (!msgs.hasMoreElements()) {
        } else {
            reading = true;
            while (msgs.hasMoreElements()) {
            Message tempMsg = msgs.nextElement();
            FrontMessage result = new FrontMessage();
            result.setFormat(tempMsg.getStringProperty("JMS_IBM_Format"));
            result.setApplication(tempMsg.getStringProperty("JMSXAppID"));
            result.setDate(tempMsg.getStringProperty("JMS_IBM_PutDate"));
            result.setTime(tempMsg.getStringProperty("JMS_IBM_PutTime"));
            result.setEncoding(tempMsg.getStringProperty("JMS_IBM_Encoding"));
            result.setMessageId(tempMsg.getJMSMessageID());
            result.setCorrelationId(tempMsg.getJMSCorrelationID());
            result.setCharSet(tempMsg.getStringProperty("JMS_IBM_Character_Set"));
            messages.add(result);
            }
        }

回答1:

When you use QueueBrowse you browse as many as the client and or provider allow you to at once. There is no option to browse parts of a message. A message is all or nothing. While you can "zero out" the body, the slow part is most likely in the retrieval of the messages.

Based off the headers/properties you are looking for, I'm assuming you are using WebSphere MQ. If so, you can gain a little more control over the browsing if you use the native WMQ API (WMQ Client for Java vs WMQ Client for JMS) to browse, but you still browse the full message.



回答2:

This is just some additional information regarding the accepted answer, it doesn't really answer the original question. This information pertains to not getting the entire IBM MQ message.

Using the WMQ API you can use options that allow you to accept truncated messages when you browse. I haven't used wireshark or tcpdump to verify that it reduces the amount of data sent over the network, but I am guessing that it would.

The options you would use are MQC.MQGMO_ACCEPT_TRUNCATED_MSG. You would also change the size of your message buffer prior go your message get. A short example can be found here: Java WMQ API example.



回答3:

No there isn't a way to get just the header information - do raise an IBM Request for enchanement if you feel this would be very useful.