views:

38

answers:

1

Hi
The javaEE 6 tutorial says that you can not use Session Bean asynchronously, then what is the purpose of @Asynchronous annotation in EJB 3.1 as this article says you can use it. Can somebody explain when to use Message Driven Bean?

thanks!

+1  A: 

Message Beans have guaranteed delivery, once a message is on a queue (Assuming the queue is persistent) it is persisted and even in case of a crash, upon startup the MessageBean will process it. In the case of asynchronous Session Beans, in case of a crash, you have lost your message, unless you handle this yourself.

In the tutorial, I disagree with:

Session beans allow you to send JMS messages and to receive them synchronously, but not asynchronously.

Putting a message on a queue is a synchronous operation (For that matter so is any method call), The semantics are really asynchronous, since you are putting the message on the queue and then forgetting about it. I guess what they mean here is that you can send a message from a session bean and then wait on the response synchronously (Probably not a good idea for the most part)

To answer your question on when to use Message Beans, you would use them to listen on a queue for async messages and then call whatever logic you needed to call with the information in the message.

Romain Hippeau