ALERT

Stop Ransomware Mid-Flight

Message-Driven Bean

Definition - What does Message-Driven Bean mean?

A message-driven bean is a component of a lightweight enterprise application that is used to process messages in asynchronous mode, where the user does not always receive immediate results. Any component can send these messages regardless of whether it uses J2EE technology.

The two distinct features that differentiate message-driven beans from session and entity beans are that message-driven beans cannot be accessed through interfaces and they have only a bean class.

Techopedia explains Message-Driven Bean

Message beans are also noted for the following characteristics:

  • Message-driven beans' instances retain no data or conversational state for a specific client.
  • All instances of a message-driven bean are equivalent, allowing the EJB container to assign a message to any message-driven bean instance. The container can pool these instances to allow streams of messages to be processed concurrently.
  • A single message-driven bean can process messages from multiple clients.

Message-driven beans are used in asynchronous communication between enterprise application components. A message is processed as follows:

  1. When a new message arrives, the enterprise JavaBeans container calls the message-driven bean’s onMessage method to process the message.
  2. The message is cast as a JMS message, which is handled based on the application’s business logic. Then, if the onMessage method wants to process the message only, it invokes a session bean. If, however, the method wants to store the message in a database, it invokes an entity bean.
  3. The message is then delivered to a message-driven bean so that the above operations become part of a single and complete transaction. A message is sometimes redelivered if there is a rollback in message processing.
Share this: