Topic
  • 1 reply
  • Latest Post - ‏2016-10-25T16:59:05Z by fjb_saper
Zelota
Zelota
1 Post

Pinned topic Message stuck in queue

‏2016-10-20T08:00:04Z | message mqqueue stuck websphere

Hello,

I'm brand new in MQ/Websphere. :) I have created a java client that read messages from a queue. It reads message well but the message stucks in the queue. Why?

Here's my pilot project code:

import com.ibm.mq.MQEnvironment;
import com.ibm.mq.MQException;
import com.ibm.mq.MQGetMessageOptions;
import com.ibm.mq.MQMessage;
import com.ibm.mq.MQPutMessageOptions;
import com.ibm.mq.MQQueue;
import com.ibm.mq.MQQueueManager;
import com.ibm.mq.constants.CMQC;
import com.ibm.mq.constants.MQConstants;
import com.ibm.mq.jms.MQConnectionFactory;
import com.ibm.mq.jms.MQTopicConnectionFactory;
import com.ibm.msg.client.wmq.WMQConstants;
import java.io.IOException;
import java.util.Hashtable;

[...]

    private void xxxReadMsg() {
        MQQueueManager queueManager = null;
        MQQueue queue = null;
        Boolean raiseError = false;
        try {
            System.out.println("xxxReadMsg starts.");
            
            Hashtable queueManagerProperties = new Hashtable();
            queueManagerProperties.clear();
            queueManagerProperties.put("hostname", "--THE_HOST_IP--");
            queueManagerProperties.put("port", 1414);
            queueManagerProperties.put("channel", "--CHANNEL_NAME--");
            queueManagerProperties.put("transport", "MQSeries"); // Client");  //CMQC.TRANSPORT_PROPERTY

            queueManager = new MQQueueManager("QMGR", queueManagerProperties);
            
            queue = queueManager.accessQueue("--QUEUE_NAME--", CMQC.MQOO_BROWSE | CMQC.MQOO_OUTPUT | CMQC.MQOO_INPUT_SHARED);

            MQGetMessageOptions opt = new MQGetMessageOptions();
            opt.options =  CMQC.MQGMO_BROWSE_HANDLE | CMQC.MQGMO_NO_WAIT | CMQC.MQGMO_ACCEPT_TRUNCATED_MSG;

            MQMessage myMessage = new MQMessage();
            myMessage.correlationId = CMQC.MQMI_NONE;
            myMessage.messageId = CMQC.MQMI_NONE;

            queue.get(myMessage, opt);

            try {
                System.out.println("myMessage.id: " + myMessage.messageId);
                System.out.println("myMessage.getMessageLength(): " + myMessage.getMessageLength());
                String sMessage = myMessage.readStringOfByteLength(myMessage.getMessageLength());
                System.out.println("sMessage: " + sMessage);
            } catch (IOException ex) {
                ex.printStackTrace();
                raiseError = true;
            }
            System.out.println("---");

        } catch (MQException ex) {
            raiseError = true;
            ex.printStackTrace();
        } finally {
            try {
                if (queue != null && queue.isOpen()) {
                    queue.close();
                }
                if (queueManager != null && queueManager.isOpen()) {
                    if (!raiseError) {
                        queueManager.backout(); //need?
                        queueManager.commit();  //need?
                    }
                    queueManager.close();
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        System.out.println("xxxReadMsg end.");
    }

What did I do wrong?

Any idea?

 

  • fjb_saper
    fjb_saper
    240 Posts

    Re: Message stuck in queue

    ‏2016-10-25T16:59:05Z  

    You are trying to use transactionality (backout and commit) but you did not specify the SYNCPOINT option in your gmo/pmo options.

    Finally you backout without ever committing the reads / gets...