Introduction
This guideline focuses on designing message-driven beans. Additional guidance on message-driven beans, such as how to
identify and model them, is provided by Guideline: Message-Driven Bean. General guidance on EJBs is provided by Guideline: Enterprise JavaBean (EJB)
Note that since message-driven beans are invoked indirectly via messages, rather than directly via interface
operations, their design entails elaborating message format and describing behavior in response to messages, and not
elaborating interface operations.
One limitation of using messaging is that the producer of a message and the consumer (the message-driven bean) cannot
participate in the same transaction. The producer can use a transaction to place the message on the queue, and the
message-driven bean can use a separate transaction to commit the results of consuming the message, but these must
always be separate transactions.
Message-driven beans can use bean-managed or container-managed transactions. Generally container-managed transactions
are simpler, and so are the preferred approach. See Guideline: Designing Enterprise JavaBeans (EJBs) for more guidance.
Each message-driven bean is an active class that may have multiple instances. Since each message-driven bean instance
runs concurrently, the processing of a message received by one instance may complete before or after a message
processed by another instance.
This means that messages can be consumed in a different order than in which they were produced. The design of
message-driven beans must take this possibility into account.
|