Create a JMS message listener

From Resin 3.0

(Difference between revisions)
Jump to: navigation, search
 
 
(One intermediate revision by one user not shown)
Line 22: Line 22:
  
 
==== resin-web.xml ====
 
==== resin-web.xml ====
<resource type="com.caucho.jms.resource.ListenerResource">
+
<code><pre>
  <init>
+
&lt;web-app xmlns="http://caucho.com/ns/resin">
      <connection-factory>${jmsFactory}</connection-factory>
+
 
   
 
   
      <destination>${queue}</destination>
+
<ejb-message-bean class="example.MyListener">
   
+
    <connection-factory>${jmsFactory}</connection-factory>
      <listener type="example.MyListener"/>
+
    <destination>${queue}</destination>
  </init>
+
  </ejb-message-bean>
</resource>
+
 
 +
&lt;/web-app>
 +
</pre></code>
 +
 
 +
== See Also==
 +
 
 +
* http://caucho.com/resin/doc/resin-messaging.xtp

Latest revision as of 11:05, 28 February 2008


Contents

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

resin-web.xml

 <web-app xmlns="http://caucho.com/ns/resin">
 
 <ejb-message-bean class="example.MyListener">
    <connection-factory>${jmsFactory}</connection-factory>
    <destination>${queue}</destination>
 </ejb-message-bean>

 </web-app>

See Also

Personal tools