Too bad these guys aren’t message-driven beans

Method calls, local or remote, are synchronous. The caller is stuck waiting until the server returns.

Message-driven beans (added in EJB 2.0) give you asynchronous communication between the client (message sender) and the server (message receiver).

In messaging terms, the sender is called the message Producer and the receiver is called the message Consumer.

With messaging, the Producer sends a message and then goes about his business. He doesn’t have to wait for the Consumer to even get the message, let alone process it.

When the Consumer gets a message, he processes it. In the meantime, the client can still have a life.

image with no caption

Message-driven bean overview

  1. Client (Producer) send a message to the messaging service.

    image with no caption
  2. Message is delivered to the Container. Client is doing other client things.

    image with no caption
  3. Container acknowledges the message to the service, and pulls a bean out of the pool to process the message.

    image with no caption
  4. Container invokes the beans onMessage() method, with the message as the argument.

  5. The bean’s transaction commits, and the Container sends the bean back to the pool. ...

Get Head First EJB 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.