Browse DevX
Sign up for e-mail newsletters from DevX


EJB Messaging, Part II: Message-Driven Beans-3 : Page 3




Building the Right Environment to Support AI, Machine Learning and Deep Learning

When an EJB application server starts, it parses the deployment descriptors and then loads and initializes the declared beans. In the case of a message bean, the container establishes a connection with the messaging provider (MOM server). Clients access message beans through the bean's JMS interface (javax.jms.MessageListener), which exposes a single method:

public void onMessage(javax.jms.Message message)

The JMS specification defines this interface as a standard interface for listening on a JMS destination. This allows the bean to asynchronously receive JMS messages published to the destination (topic or queue) with which this bean has registered. In this way, the message bean functions as a full-fledged JMS client, indistinguishable from any other JMS client.

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 into the method.

In addition to functioning as asynchronous JMS clients, message beans also support message concurrency. Since message beans are stateless and managed by the container, they can both send and receive messages concurrently (the container simply grabs another bean out of the pool). This, combined with the inherent scalability of EJB application servers, produces a very robust and scalable enterprise messaging solution.

Thanks for your registration, follow us on our social networks to keep up-to-date