aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes problem JMS request reply pattern in CMT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "problem JMS request reply pattern in CMT" Watch "problem JMS request reply pattern in CMT" New topic
Author

problem JMS request reply pattern in CMT

Rahul Ba
Ranch Hand

Joined: Oct 01, 2008
Posts: 205
I have following code...My Stateless bean is CMT.When, I do the bean as BMT
,the following code works fine....I know there is Transaction concept in JMS request reply pattern. As when we send message that time we should commit the Transaction and while receiving the transaction again start new transaction...I did same in following code, but receive method never gets the reply....it thrwos the exception....



private String sendMessage(Serializable payload) {

try{
Context ctx = new InitialContext(env);
conn = getJmsConnection();

org.jboss.mq.SpyQueue orderQueue =
(org.jboss.mq.SpyQueue) ctx.lookup(SCHEDULER_LISTENER_QUEUE);
session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
conn.start();
ObjectMessage message = session.createObjectMessage();
message.setObject(payload);
replyQueue = session.createTemporaryQueue();
message.setJMSReplyTo(replyQueue);
producer = session.createProducer(orderQueue);

producer.send(message);
System.out.println("Request Has been Sent");
actionResult= receiveMessage(replyQueue);
}catch(Exception e){

}finally {
closeSession(session);
closeConnection(conn);

}
return actionResult;
}


@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public String receiveMessage(Destination replyQueue ){

QueueSession session = null;

if(replyQueue == null){
System.out.println("I am null");
}


try{
if (replyQueue != null) {
MessageConsumer replyConsumer = session.createConsumer(replyQueue);
javax.jms.Message responseMessage = replyConsumer.receive(10000L);
if (responseMessage != null) {
System.out.println("Response received");
} else {
System.out.println("Response not received due to timeout");
}
replyConsumer.close();


if (responseMessage instanceof TextMessage) {
TextMessage requestMessage = (TextMessage) responseMessage;
}
}
}catch(Exception e){

}
return "hello";
}
Gast�n Acevedo
Greenhorn

Joined: Dec 08, 2008
Posts: 1
Im very new to jms but...
The requires new transaction in the method for receive the reply only works if you obtain a new reference to the bean, not only when you call the method in the same instance.

maybe this can help
http://blogs.sun.com/fkieviet/entry/request_reply_from_an_ejb
 
jQuery in Action, 2nd edition
 
subject: problem JMS request reply pattern in CMT