![]() | ![]() | ![]() |
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() | ![]() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
Resin 3.1 Documentation Examples Changes Quercus Database Amber EJB SOA/ESB IoC JMS Servlet JMX Hessian Security JMS/PHP Send JMS/PHP Receive JMS Listener JMS IOC Listener |
Introduces the JMS message listener configured with JCA. Files in this tutorial
OverviewMessaging lets a servlet delegate processing to a batch process either on the same machine or on a separate machine. The servlet creates a message and sends it to a queue. The servlet immediately completes and when the batch process is ready, it processes the message. Messaging is therefore comprised of three main components:
Producer (MessageServlet)In this example, the Producer is a Servlet which sends a simple message.
The Producer uses a String message = "sample message"; MessageSender sender = ...; // JNDI lookup sender.send(null, message); In this configuration, the The Consumer (MyListener)The Queue delivers message to the Consumer one by one. When the Consumer finishes processing a message the Queue will deliver the next available message. The Consumer implements In this example, the Consumer just logs the message. package example; import java.util.logging.Logger; import java.util.logging.Level; import javax.jms.Message; import javax.jms.TextMessage; import javax.jms.MessageListener; public class MyListener implements MessageListener { private static final Logger log = Logger.getLogger(MyListener.class.getName()); public void onMessage(Message message) { try { TextMessage textMessage = (TextMessage) message; log.info("received: " + textMessage.getText()); _lastMessage = textMessage.getText(); } catch (Throwable e) { log.log(Level.WARNING, e.toString(), e); } } } ConfigurationThe configuration is responsible for three things:
The JMS The <connection-factory> configures the MessageSender and saves it in JNDI. The <message-listener> and <endpoint-factory> configures the MessageListener. <web-app xmlns="http://caucho.com/ns/resin"> <connector> <type>com.caucho.jms.jca.ResourceAdapterImpl</type> <resource-adapter> <init> <connection-factory resin:type="com.caucho.jms.ConnectionFactoryImpl"/> <destination resin:type="com.caucho.jms.memory.MemoryQueue"/> </init> </resource-adapter> <connection-factory jndi-name="jms/sender" type="com.caucho.jms.jca.MessageSenderManager"/> <message-listener type="com.caucho.jms.jca.MessageListenerSpec"> <endpoint-factory type="com.caucho.jms.jca.ListenerEndpointFactory"> <init> <listener resin:type="example.MyListener"/> </init> </endpoint-factory> </message-listener> </connector> </web-app>
|