Sample Message-Driven Bean

Let's do an end-to-end implementation and testing of a Message-Driven bean that will simply print out the information about the received messages. The same class will be deployed as two beans: one will listen on a queue and the other will subscribe to a topic. We'll go through the whole process of creating and deploying the beans, issuing test messages, and monitoring how they behave.

The bean class is straightforward, as shown in Listing 23.1.

Listing 23.1. SnoopMDB.java
 import java.util.*; import javax.ejb.*; import javax.jms.*; import javax.naming.*; public class SnoopMDB implements MessageDrivenBean, MessageListener { private MessageDrivenContext context = null; private Context jndiContext = null; public void ejbCreate ...

Get BEA WebLogic Server™ 8.1 Unleashed 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.