Message-Driven Beans
Although session beans and web components can act as JMS
producers, these components can only consume JMS messages
synchronously using one of the MessageConsumer.receive()
methods. Calling the
receive()
methods causes the JMS
client to block on the currently running thread and wait for a
message.[12] These methods are used to consume messages synchronously,
whereas MessageListener
objects are
used to consume messages asynchronously.
Only the message-driven bean and application client components can both produce and consume asynchronous messages. The web and session components cannot act as asynchronous JMS consumers because they are driven by synchronous request/reply protocols, not asynchronous messages. Web components respond to HTTP requests while session beans respond to Java RMI-IIOP requests.
The fact that neither web components nor session beans can asynchronously consume JMS messages was one of the things that originally led to development of the message-driven bean. The MDB provides Java EE developers with a server-side JMS consumer that can consume asynchronous messages, something that wasn’t supported in the early versions of Java EE.
While most JMS vendors provide the message-brokering facilities for routing messages from producers to consumers, the responsibility for implementing JMS clients is left to the application developer. In many cases, the JMS clients that consume and process messages need a lot of infrastructure in order to be robust, secure, ...
Get Java Message Service, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.