Message-Driven Bean

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.

Advertisements

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.
Advertisements

Related Terms

Margaret Rouse

Margaret is an award-winning technical writer and teacher known for her ability to explain complex technical subjects to a non-technical business audience. Over the past twenty years, her IT definitions have been published by Que in an encyclopedia of technology terms and cited in articles by the New York Times, Time Magazine, USA Today, ZDNet, PC Magazine, and Discovery Magazine. She joined Techopedia in 2011. Margaret's idea of a fun day is helping IT and business professionals learn to speak each other’s highly specialized languages.