Author |
Message
|
usman.usmani@gmail.com |
Posted: Sat Sep 16, 2006 3:54 am Post subject: Temporary queue problem time out before recieving the messag |
|
|
Newbie
Joined: 20 Jun 2006 Posts: 8
|
Hi,
I am using WAS 6.0.2.11. I am using default messages to communicate
between applications. I need to communicate synchronously between two
services/application deployed A and B. when i am sending a message from
A to B to the destination B listens to I create a temporary queue and
from A and set it as JMSReplyTo destination send it to B. B sends me
message successfully where as A times out imediately after I send the
message irrespective of the timeout i specify although i am listening message using the following code. Can
any one tell me the solution or workarround.
Following is the code that I use at A.
InitialContext context = null;
try {
context = new InitialContext();
ConnectionFactory factory = (ConnectionFactory)
context.lookup("jms/QCFMQGateWay");
Destination destination = (Destination)
context.lookup("jms/MQGWQueue");
Connection connection = factory.createConnection();
Session session =
connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(destination);
Destination replyQueue = session.createTemporaryQueue();
BytesMessage message = session.createBytesMessage();
message.setJMSReplyTo(replyQueue);
MessageConsumer replyConsumer = session.createConsumer(replyQueue);
byte [] bytes =
ObjectSerializer.serializeObject(transferObjectBase);
message.writeBytes(bytes);
producer.send(message);
System.out.println("=======================================================Â====");
System.out.println("The connection state is " + connection);
System.out.println("Listening on temporary destination = " +
replyQueue);
System.out.println("=======================================================Â====");
connection.start();
BytesMessage msg = (BytesMessage)replyConsumer.receive(60000);
System.out.println("=======================================================Â====");
System.out.println("The connection state is " + connection);
System.out.println("Message revieved from replyQueue = " + msg);
System.out.println("=======================================================Â====");
if(msg!=null)
{
String reply = getBodyAsString(msg);
System.out.println("The confirmation reply message is " + msg);
if(reply == null || reply.trim().equals(""))
throw new CommunicationException("Unidentified confiramtion reply
format");
else if(reply.equals("Failed"))
throw new CommunicationException("Failed to send request. Please
check the logs");
}else
throw new CommunicationException("Failed to recieve confirmation
message from gateway");
} catch (NamingException e) {
throw new CommunicationException("Cannot find initial Context" ,e);
} catch (JMSException e) {
throw new CommunicationException("Error Occured",e);
} catch (IOException e) {
throw new CommunicationException("cannot serialize object",e);
}
Following is the code at service B that sends a sync response
Destination dest = msg.getJMSReplyTo();
if (dest!=null){
log.debug("reply
destination is :"+dest);
InitialContext ctx = new
InitialContext();
/****
*
* specify the connection factory
name
*/
QueueConnectionFactory factory =
(QueueConnectionFactory)ctx.lookup("jms/QCFMQGateWay");
// create a connection and session
Connection connection =
factory.createQueueConnection();
log.debug("connection in MQGateway
is "+connection);
Session session =
connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer =
session.createProducer(dest);
BytesMessage byteReplyMsg =
session.createBytesMessage();
byteReplyMsg.writeBytes(replymsg.getBytes());
producer.send(msg);
log.debug("the reply message has
been sent to :"+dest);
}else {
/// to do send to a
specified destination for errors
log.debug("destination
is null ---- not going to send");
} _________________ Usmani |
|
Back to top |
|
 |
jefflowrey |
Posted: Sat Sep 16, 2006 4:49 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
I don't understand what JMS provider you are using. You say "default messages" and then you say "temporary queue".
Also, am I correct that you are trying to both send a request and receive a reply inside the same transaction? How will the request ever get committed?  _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
usman.usmani@gmail.com |
Posted: Sat Sep 16, 2006 6:26 am Post subject: |
|
|
Newbie
Joined: 20 Jun 2006 Posts: 8
|
I am sorry for not being clear first time. I am using Default messaging inside by creating a bus and destinations over the bus. I have deployed 2 applications A and B where B listens to a destination. A wants to communicate with B. A creates a temporary queue and sets it as JMSReplyTo in the message it sends and than sends the message to B and starts listening on the temp queue. B does some processing which takes only a few milliseconds i.e. less than time out for a and sends a message to A on the same reply to destination it recieved. now A is not revcieving the reply.
I hope the problem is clearified I cannot understand by transaction what are you reffering to. If you can help I shall stand grateful. _________________ Usmani |
|
Back to top |
|
 |
jefflowrey |
Posted: Sat Sep 16, 2006 7:39 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Messages being SENT in a transaction are not SENT until the Transaction is committed. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
usman.usmani@gmail.com |
Posted: Wed Sep 20, 2006 12:40 am Post subject: |
|
|
Newbie
Joined: 20 Jun 2006 Posts: 8
|
Found the solution after getting the connection you have to start the connection by connection.start() dont understand pretty much why but this is the way it works _________________ Usmani |
|
Back to top |
|
 |
|