Reputation: 37
I am trying to implement read ahead functionality for my client. They get a bunch of messages from IBM MQ Queues. Trying to read multiple messages at a time since they are non-persistent messages. I am unable to call the setReadAhead method provided by MQDestination.I tried finding any alternate way of doing this, but looks like no one uses ibm mq that much. Maybe I am doing it wrong. Using version ibm 9.1, and currently without the commented line in the code it reads messages one at a time.
Any help is appreciated!
Thanks
void initMQConnection(String queueName) throws JMSException {
MQQueueConnectionFactory factory = new MQQueueConnectionFactory();
factory.setTransportType(JMSC.MQJMS_TP_CLIENT_MQ_TCPIP);
factory.setQueueManager(jms_property.getProperty(queueManager));
factory.setHostName(jms_property.getProperty(host));
factory.setPort(jms_property.getProperty(port));
factory.setChannel(jms_property.getProperty(channel));
QueueConnection qConn = factory.createQueueConnection(username, password);
QueueSession session = qConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue(queueName);
((MQDestination) destination).setReadAheadAllowed(); // --> Unable to use this method (Cannot Resolve Method)
MessageConsumer mc = session.createConsumer(destination);
qConn.start();
}
In the code where I am using messageConsumer, I call
mc.recieve(1000);
Upvotes: 0
Views: 857
Reputation: 15263
You can read/get only one message at a time, not multiple messages.
The read ahead feature enables underlying MQ client library to receive multiple non-persistent messages and buffer in it's memory. This is done to avoid MQ client making calls over the network to MQ server to receive one message at a time. The received messages are buffered in the MQ client memory and delivered one at a time to client application when a consumer.receive() call is made. Read more here on Read Ahead: https://www.ibm.com/docs/en/ibm-mq/9.3?topic=application-using-read-ahead-in-client
ReadAhead is a IBM MQ speicific function. You will need to cast the JMS Destination to MQQueue type. For example:
((MQQueue) destination).setReadAheadAllowed();
I don't see what packages have been imported, it appears that com.ibm.mq.MQDestination
has been imported. setReadAheadAllowed
is not a member of com.ibm.mq.MQDestination
class. Instead it is a member of com.ibm.mq.jms.MQDestination
class.
Upvotes: 1