Message listener
From Resin 3.0
(Difference between revisions)
Line 1: | Line 1: | ||
+ | [[Category:JMS]] | ||
+ | |||
== Writing a Message Listener == | == Writing a Message Listener == | ||
Revision as of 04:07, 30 November 2005
Writing a Message Listener
The JMS MessageListener interface has a single method onMessage(Message)
.
A simple message application can implement that message listener waiting to receive messages from the queue.
MyListener.java
import javax.jms.*; public class MyListener implements MessageListener { public void onMessage(Message message) { TextMessage text = (TextMessage) message; System.out.println("Message: " + text.getText()); } }
Configuring a Listener Resource
<resource type="com.caucho.jms.resource.ListenerResource"> <init> <connection-factory>${jmsFactory}</connection-factory> <destination>${queue}</destination> <listener type="example.MyListener"/> </init> </resource>