views:

26

answers:

2

Hi,

I have a system based on JMS queues that enable the whole system to work in async fashion.

Now, for some periodic tasks I need to execute some non time consuming tasks in sync way, so that I can do something with the result right away, without using a database for storing request and pairing it with result (as with async operation).

The code itself is not a problem, but the fact that EJBs run container transactions, which means that the producer.send() code and consumer.receive() will not execute sequentially (i.e. message is not sent, so nothing to receive in the receive() few lines bellow).

How can I have JMS message sent and response received in sync fashion in stateless EJB3 environment?

Thanks for answers,

Bozo

+1  A: 

You could switch your bean to use Bean-Managed Transactions.

@MessageDriven
@TransactionManagement(BEAN)
public class MyMDB implements MessageListener {

  // this is optional
  @Resource
  private UserTransaction ut;

  //...

}
David Blevins
A: 

You should be aware of transaction contexts in ejbs that affect sending request/reply messages via jms..

"The solution would be to suspend the transaction, create a new transaction, send the request, commit the new transaction, unsuspend the first transaction, and continue."

in the url below, you will find the problem statement and a solution. BTW, this applies to both container managed and bean managed transactions ..

http://blogs.sun.com/fkieviet/entry/request_reply_from_an_ejb

lapax