O'Reilly logo

Sams Teach Yourself J2EE™ in 21 Days by Peter Roxburgh, Andy Longshaw, Debbie Law, Dan Haywood, Martin Bond

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

Writing a Simple Message-Driven Bean

As you work through this section, you will create a Message-driven bean that that simply prints out the contents of a text message on screen.

So that the Message-driven bean can work asynchronously you will employ the MessageListener interface. This interface and the associated onMessage() method, which is invoked each time a message is available at the destination, were fully described in Day 9.

Implementing the Interfaces

As already stated, all Message-driven beans must implement the MessageDrivenBean and MessageListener interfaces.

import javax.ejb.*;
import javax.jms.*;
public class MDBPrintMessage implements MessageDrivenBean, MessageListener {
// class body not shown – see listing 10.1
}

Just like ...

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