This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
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 REST with Spring (video course) 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

problem JMS request reply pattern in CMT

Rahul Ba
Ranch Hand

Joined: Oct 01, 2008
Posts: 206
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 thrwos the exception....

private String sendMessage(Serializable payload) {

Context ctx = new InitialContext(env);
conn = getJmsConnection(); orderQueue =
session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
ObjectMessage message = session.createObjectMessage();
replyQueue = session.createTemporaryQueue();
producer = session.createProducer(orderQueue);

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

}finally {

return actionResult;

public String receiveMessage(Destination replyQueue ){

QueueSession session = null;

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

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");

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

return "hello";
Gast�n Acevedo

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
I agree. Here's the link:
subject: problem JMS request reply pattern in CMT
It's not a secret anymore!