Sheeraz Junejo [
http://community.jboss.org/people/sjunejo] created the discussion
"[HELP] Unable to consume reply message from MQ Queue"
To view the discussion, visit:
http://community.jboss.org/message/574484#574484
--------------------------------------------------------------
| | Hi,
I am having problem consuming messages from MQ Server Queue. I am using WebSphere MQ
Server 7 with my web application to put messages on IN Queue which will then Consume by
my MDB deployed on jBoss and put reply back on OUT Queue.
My web application is deployed on jBoss 4.2.3 and I am using MQ Resource Adapter to
connect to MQ Server.
I am able to successfully put message on IN Queue where MDB is listening which consume
the messages, do some processing and put reply back on OUT Queue where my web application
is waiting for a response but it get TIMED OUT. I mean I can see the response in MQ
Explorer which is just sitting there waiting to be consumed but my web application can
not recognize for some reason.
I have tried with simpler Co-relation ID like '1' but didn't work. I am using
following code to do all of the above;
| *Code:* |
|
Connection connection = null;
Session session = null;
MessageProducer producer = null;
Destination reqQueue = null;
Destination repQueue = null;
try {
timeStart = System.currentTimeMillis();
InitialContext ctx = new InitialContext(); // Initial Context of type JMS Connection
Factory
Object factoryObj = ctx.lookup(jmsCxFactory);
ConnectionFactory cxf = (ConnectionFactory)factoryObj;
connection = cxf.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
connection.start();
_serviceLocator = new ServiceLocator(); // Look up queues
reqQueue = _serviceLocator.lookupDestination("queue/INQueue");
repQueue = _serviceLocator.lookupDestination("queue/OUTQueue");
producer = session.createProducer(reqQueue); // Register a producer
Message jmsMsg = session.createTextMessage(message); // Assign request to Message object
so we can send it to Database Server later.
jmsMsg.setJMSReplyTo(repQueue); // Preparing a class to wait for a response on Response
queue
producer.setDisableMessageID(false); // Make sure messages gets an id
String correlationId = "1"; // Get and set unique Correlation ID so we can
receive correct messages
jmsMsg.setJMSCorrelationID(correlationId);
jmsMsg.setStringProperty("FORMAT", pingLevel); // Set the message format
producer.send(jmsMsg); // Put message on Queue
MessageConsumer receiver = session.createConsumer(repQueue,
"JMSCorrelationID='" + correlationId + "'"); // Now receive
message
long JMSConnectionTimeout = 5000L; // Set timeout value - Default 10 Sec.
Message reply = receiver.receive(JMSConnectionTimeout); // Now receive a response
if (reply instanceof TextMessage) {
String response = ((TextMessage)reply).getText();
passedReq++; // Increment in the passed request counter
} else {
finalResponse += "Request : Timed Out..."; <--- Always timed Out and control
ends up here
failedReq++; // Increment in number of time out requests
}
}
catch (NamingException e) {
finalResponse += "Error Occured : Naming Exception - " + e.getMessage();
}
catch (JMSException e) {
finalResponse += "Error Occured : JMS Exception - " + e.getMessage();
}
catch (RuntimeException e) {
finalResponse += "Error Occured : Runtime Exception - " + e.getMessage();
}
finally {
closeResource(producer);
closeResource(connection);
closeResource(session);
}
|
Does anyone know what could be the reason and why its happening? Your help and comments
will be appreciated.
Thanks
--
SJunejo |
|
|
| |
|
|
|
--------------------------------------------------------------
Reply to this message by going to Community
[
http://community.jboss.org/message/574484#574484]
Start a new discussion in JBoss ESB Development at Community
[
http://community.jboss.org/choose-container!input.jspa?contentType=1&...]