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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.