📄 resin-messaging.xtp
字号:
</ejb-message-bean></web-app></example></s2><s2 title="Cluster Client Topic"><p>The client topic distributes messages to server topics in acluster. Normally, only the sending methods are used for the clienttopic; the receiving message beans are handled by the server topics.</p><p>The client topic needs to configure the cluster of the server topics.The cluster can be different from the client's own cluster.</p><example title="resin-web.xml - client topic"><web-app xmlns="http://caucho.com/ns/resin"> <jms-topic name="myTopic" uri="client:cluster=message-tier"/> <jms-connection-factory uri="resin:"/></web-app></example></s2>--></s1><s1 title="ConnectionFactory"><p>The <code>ConnectionFactory</code> resource defines the JMS factoryfor creating JMS connections.</p><example title="resin-web.xml - ConnectionFactory resource"><web-app xmlns="http://caucho.com/ns/resin"> <jms-connection-factory name="jms/factory" uri="resin:"/></web-app></example><!-- XXX: ??<p>If an application creates a named queue or topic using the the JMS Session,Resin's default behaviour is to create a memory queue or topic. The <a href="#jdbc-manager">jdbc-manager</a> configuration of the connection factory causes creation of a jdbc queue or topic instead.</p><example title="ConnectionFactory resource"><resource jndi-name="jms/factory" type="com.caucho.jms.ConnectionFactoryImpl"/> <init> <jdbc-manager> <data-source>jdbc/database</data-source> </jdbc-manager> </init></resource></example><deftable-childtags><tr><td>client-id</td> <td>clientID value for durable subscriptions</td> <td>pseudo-random generated value</td> </tr><tr><td>jdbc-manager</td> <td>Use jdbc queues and topics for queues and topics created using the JMS Session object, see <a href="#jdbc-manager">jdbc-manager</a></td> <td>use a memory queue for created queues and topics</td> </tr></deftable-childtags>--></s1><s1 title="BlockingQueue API"><p>Resin's queues implementthe <code>java.util.concurrent.BlockingQueue</code> API.Since the queues are registered with <a href="resin-ioc.xtp">Resin-IoC</a>it's possible to use the <code>BlockingQueue</code> API directlywithout the JMS API.</p><example title="TestServlet for JMS/BlockingQueue">package example;import java.util.concurrent.BlockingQueue;import java.io.*;import javax.servlet.*;import javax.webbeans.*;public class TestServlet extends GenericServlet { private @In BlockingQueue _queue; public void service(ServletRequest req, ServletResponse res) throws IOException, ServletException { PrintWriter out = res.getWriter(); _queue.offer("test message"); out.println("receive: " + _queue.poll()); }}</example><p>The resin-web.xml configuration for the <code>BlockingQueue</code>API is simple, only requiring the <jms-queue> tag. Because the<code>BlockingQueue</code> uses Resin's JMS queue implementation directly,it already knows where to get the <code>ConnectionFactory</code>.</p><example title="resin-web.xml configuration for memory BlockingQueue"><web-app xmlns="http://caucho.com/ns/resin"> <jms-queue uri="memory:"/></web-app></example><s2 title="BlockingQueue for 3rd party JMS"><p>The <code>BlockingQueue</code> API is also available for other JMSproviders. You'll need to configure a <code>JmsBlockingQueue</code> inthe resin-web.xml to take advantage of it.</p><example title="Example: BlockingQueue WEB-INF/resin-web.xml"><web-app xmlns="http://caucho.com/ns/resin"> <resource-adapter class="org.apache.activemq.ra.ActiveMQResourceAdapter"> <init server-url="vm://localhost"/> </resource-adapter> <connection-factory uri="activemq:" name="factory"/> <jms-queue uri="activemq:" name="queue"> <init physicalName="queue.test"/> </jms-queue> <bean name="test" class="com.caucho.jms.queue.JmsBlockingQueue"> <init> <factory>${factory}</factory> <destination>${queue}</destination> </init> </bean></web-app></example></s2></s1><s1 title="Message Driven Beans"><p>At some point, the application needs to receive messages from theand process them. Message driven beans provides a reliable, pooledframework for receiving messages. Applications just need to implementa simple listener interface, and register to listen with a queue or topic.</p><def title="javax.jms.MessageListener">package javax.jms;public interface MessageListener { public void onMessage(Message message);}</def><p>The implementation class can use any <a href="resin-ioc.xtp">Resin IoC</a>capability, including injection, transaction annotations or interception.For example, a simple listener might use <a href="amber.xtp">Amber/JPA</a> tostore messages in a database.</p><example title="demo/MyListener.java">package demo;import javax.jms.*;import javax.persistence.*;import javax.webbeans.*;public class MyListener implements MessageListener{ private @In EntityManagerFactory _factory; public void onMessage(Message msg) { ObjectMessage oMsg = (ObjectMessage) msg; String value = oMsg.getObject(); EntityManager em = _factory.createEntityManager(); try { em.persist(new MyEntry(value)); } finally { em.close(); } }}</example><p>The configuration in the resin-web.xml file will connect the<code>MyListener</code> class with the queue. In this case, we'lluse the simple memory queue.</p><example title="WEB-INF/resin-web.xml"><web-app xmlns="http://caucho.com/ns/resin"> <jms-connection-factory uri="resin:"/> <jms-queue name="my_queue" uri="memory:"/> <ejb-message-bean class="demo.MyListener"> <destination>${my_queue}</destination> </ejb-message-bean></web-app></example><p>The <code><ejb-message-bean></code> tag configures the message beanpool with the application's listener specified by the <code>class</code>.Resin will automatically create several <code>MyListener</code> instancesto process any queue messages. The <code><destination></code> tagspecifies the queue to use.</p><p>Because the <code><ejb-message-bean></code> is a Resin IoC bean, itcan use an optional <code><init></code> block to configure anyparameters of <code>MyListener</code>.</p></s1><s1 title="JCA - Java Connector Architecture (.rar files)"><p>The Java Connector Architecture is a driver architecture whichconnects JMS providers like <a href="http://wiki.caucho.com/ActiveMQ">ActiveMQ</a>with Resin's message driven beans and JMS sessions. The JCA driverwill configure a <a href="http://wiki.caucho.com/Resource_Adapter">resourceadapter</a> and an <a href="http://wiki.caucho.com/Activation_Spec">activationspec</a> to select a queue.</p><p>The resource adapter is the JCA driver's main service. It handlesthreading, socket connections, and creates any endpoints.</p><s2 title="JCA for message driven beans"><p>The activation specification configures the JCA driver with amessage-driven bean. The configuration looks like:</p><example title="WEB-INF/resin-web.xml ActiveMQ"><web-app xmlns="http://caucho.com/ns/resin"> <resource-adapter class="org.apache.activemq.ra.ActiveMQResourceAdapter"> <init server-url="vm://localhost"/> </resource> <ejb-message-bean class="qa.MyListener"> <activation-spec class="org.apache.activemq.ra.ActiveMQActivationSpec"> <init physical-name="queue.test"/> </activation-spec> </ejb-message-bean></web-app></example><p>Resin can also provide shortcuts for the driver classes using theuri syntax:</p><example title="WEB-INF/resin-web.xml ActiveMQ"><web-app xmlns="http://caucho.com/ns/resin"> <resource-adapter uri="activemq:"> <init server-url="vm://localhost"/> </resource> <ejb-message-bean class="qa.MyListener"> <activation-spec uri="activemq:"> <init physical-name="queue.test"/> </activation-spec> </ejb-message-bean></web-app></example></s2></s1><s1 title="Third-party JMS providers"><ul><li><a href="http://wiki.caucho.com/ActiveMQ">ActiveMQ and Resin</a></li></ul></s1></body></document>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -