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 ...
Get Sams Teach Yourself J2EE™ in 21 Days 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.