Queue Server: ActiveMQ, Protocol: AMQP API: Apache QPID client JMS 0.3.0
In normal case, It is working fine for me and fetch the message in few milliseconds.
Facing issue in below scenario:
- Assume queue name : TESTQUEUE
- it has 500 pending messages in queue with JMSCorrelationID
- Fetching a message with JMSCorrelationID using qpid API.
It takes around min 25 sec to retrieve the message.
What should I do in this case?
// LOGIC: declaration
Connection connection = null;
MessageConsumer consumer = null;
MetaData objMetaData = new MetaData();
String strReturnData = "";
String user = "";
String password = "";
String host = "";
int port = 0;
ConnectionFactoryImpl factory = null;
Session session = null;
Destination destination = null;
Message msg = null;
try {
// LOGIC: set the connection details
user = objMetaData.getMetaData(CommonConstant.QUEUE_USERNAME);
password = objMetaData.getMetaData(CommonConstant.QUEUE_PASSWORD);
host = objMetaData.getMetaData(CommonConstant.QUEUE_HOST);
port = Integer.parseInt(objMetaData.getMetaData(
CommonConstant.QUEUE_PORT).trim());
// LOGIC: Initialize the connection factory with connection details
factory = new ConnectionFactoryImpl(host, port, user, password, strCorelationId);
// LOGIC: create connection
connection = factory.createConnection();
// LOGIC: create session
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// LOGIC: initialize destination with queue name
destination = (Destination) session.createQueue(strQueueName);
// LOGIC: open connection
connection.start();
// LOGIC: set correlation id
consumer = session
.createConsumer(
destination,"JMSCorrelationID ='"+ strCorelationId + "'");
// LOGIC: get message
if (blnIsRequestModeSync) {
msg = consumer.receive((1000 * 60 * 2));
} else {
msg = consumer.receive(30000);
}
// LOGIC: check message type
if (msg instanceof TextMessage) {
// LOGIC: when text message
TextMessage txtmsg = (TextMessage) msg;
//System.out.println("TEXT MSG: " + txtmsg.getText());
strReturnData = txtmsg.getText();
} else {
// LOGIC: when object message
ObjectMessage objmsg = (ObjectMessage) msg;
//System.out.println("Object MSG:" + objmsg);
strReturnData = (null != objmsg ? objmsg.toString() : "");
}