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.
Should I call session's commit() method? If so where should I call inside while loop for each message or outside the while loop?
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();
}
}
}
}