Alagammal P
Alagammal P

Reputation: 909

JMS to receive message- MQ Error code 2024 - message from queue are not getting removed

I am using websphere application server 8.5

I have tried to recieve the messages from queue.The queue may contain multilple messages. I want to read all at once.

I recive the error WebSphere MQ call failed with compcode '2' ('MQCC_FAILED') reason '2024' ('MQRC_SYNCPOINT_LIMIT_REACHED') though I read messages.

  1. Should I call session's commit() method? If so where should I call inside while loop for each message or outside the while loop?

  2. createQueueSession(true, 0): Will there be any corrections in the arguments to be passed in this method in both Producer and consumer end?

Approach:

import javax.naming.InitialContext;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.QueueSession;
import javax.jms.QueueReceiver;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;

public class Receiver
{
    @Resource(lookup = "jms/ConnectionFactory")
    private static QueueConnectionFactory connectionFactory;

    @Resource(lookup = "jms/Queue")
    private static Queue queue;

    public void readQueueMessages() {                                                                   
        try {
            // create a queue connection
            QueueConnection queueConn = connFactory.createQueueConnection();

            // create a queue session
            QueueSession queueSession = queueConn.createQueueSession(true, 0);

            // create a queue receiver
            QueueReceiver queueReceiver = queueSession.createReceiver(queue);

            // start the connection
            queueConn.start();

            // receive a message
            while(true) {
                TextMessage message = (TextMessage) queueReceiver.receive(180000);
                if (message != null) { 
                    if (message instanceof TextMessage) {
                        // print the message
                        System.out.println("received: " + message.getText());
                    } else {
                        break;
                    }
                } else {
                    break;
                }
            }
        } catch(JMSException exp) {
            // Handle this exception
        } finally {      
            if(queueConn != null) {                                                     
                // close the queue connection
                queueConn.close();
            }
        }
    }
}

Upvotes: 1

Views: 3542

Answers (1)

JoshMc
JoshMc

Reputation: 10672

The queue manager has a parameter MAXUMSGS which is the maximum uncommitted messages for any client, this defaults to a value of 10000. When you receive MQRC_SYNCPOINT_LIMIT_REACHED this means that you have reached that limit.

Typically you would commit once you have processed the message, in your example this would be after printing it out. Since all persistent messages are written to disk and disk can slow things down, you can tune for performance by committing multiple messages at one time. Keep in mind that if your program crashes before the messages are committed they will be rolled back to the queue and processed the next time you start your program, because of this you would likely want to limit the number of uncommitted messages.


Since you are using WebSphere Application Server you should consider using a MDB rather than write your own. The MDB will connect to the queue and wait for messages, read them from the queue and dispatch them to your own onMessage Java method to process messages.

I did a search and here are a couple links that may be helpful and I'm sure you can find others that discuss how to setup a MDB:

  1. Chris Andrews presented a session "Using IBM WebSphere Application Server and IBM WebSphere MQ Together"
  2. Craig St. Jean has a blog post "WebSphere 8.5, MQ, Spring, and Message-Driven Beans! Part 1"

Upvotes: 3

Related Questions