Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem JMS request reply pattern in CMT

 
Rahul Ba
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic