What is a Message Driven Bean, What functions does a message driven bean have and how do they work in collaboration with JMS?
Message driven beans will provide asynchrony to EJB based applications by acting as JMS message consumers. A message bean is associated with a JMS topic or queue and receives JMS messages sent by EJB clients or other beans.
Unlike entity beans and session beans, message beans do not have home or remote interfaces. Instead, message driven beans are instantiated by the container as required. Like stateless session beans, message beans maintain no client-specific state, allowing the container to optimally manage a pool of message-bean instances.
To receive JMS messages, message driven beans implement the javax.jms.MessageListener interface, which defines a single "onMessage()" method.
When a message arrives, the container ensures that a message bean corresponding to the message topic/queue exists (instantiating it if necessary), and calls its onMessage method passing the client's message as the single argument. The message bean's implementation of this method contains the business logic required to process the message:
public void onMessage(javax.jms.Message message)
// code to handle message
Note that session beans and entity beans are not allowed to function as message beans.