Message-Driven EJB Example

Let's now develop a simple message-driven EJB to receive text messages from a JMS queue and print the messages to the server's stderr.

The MessageDrivenBean class includes the four required methods. The onMessage method receives the JMS message and prints the associated text. For this simple example, any error is simply printed to the server's stderr.

MessagePrinterBean Class

 package com.learnweblogic.examples.ch10.textmessage; import javax.ejb.MessageDrivenBean; import javax.ejb.MessageDrivenContext; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.MessageListener; import javax.jms.TextMessage; public class MessagePrinterBean implements MessageDrivenBean, MessageListener { private MessageDrivenContext ...

Get J2EE™ Applications and BEA™ WebLogic Server™ 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.