O'Reilly logo

Head First EJB by Bert Bates, Kathy Sierra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required