⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 resin-messaging.xtp

📁 RESIN 3.2 最新源码
💻 XTP
📖 第 1 页 / 共 2 页
字号:
  &lt;/ejb-message-bean>&lt;/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">&lt;web-app xmlns="http://caucho.com/ns/resin">  &lt;jms-topic name="myTopic" uri="client:cluster=message-tier"/>  &lt;jms-connection-factory uri="resin:"/>&lt;/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">&lt;web-app xmlns="http://caucho.com/ns/resin">  &lt;jms-connection-factory name="jms/factory" uri="resin:"/>&lt;/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">&lt;resource jndi-name="jms/factory"           type="com.caucho.jms.ConnectionFactoryImpl"/&gt;  &lt;init&gt;    &lt;jdbc-manager&gt;      &lt;data-source&gt;jdbc/database&lt;/data-source&gt;    &lt;/jdbc-manager&gt;  &lt;/init&gt;&lt;/resource&gt;</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 &lt;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">&lt;web-app xmlns="http://caucho.com/ns/resin">  &lt;jms-queue uri="memory:"/>&lt;/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">&lt;web-app xmlns="http://caucho.com/ns/resin">  &lt;resource-adapter class="org.apache.activemq.ra.ActiveMQResourceAdapter">      &lt;init server-url="vm://localhost"/>  &lt;/resource-adapter>   &lt;connection-factory uri="activemq:" name="factory"/>    &lt;jms-queue uri="activemq:" name="queue">       &lt;init physicalName="queue.test"/>   &lt;/jms-queue>   &lt;bean name="test" class="com.caucho.jms.queue.JmsBlockingQueue">    &lt;init>      &lt;factory>${factory}&lt;/factory>      &lt;destination>${queue}&lt;/destination>    &lt;/init>  &lt;/bean>&lt;/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">&lt;web-app xmlns="http://caucho.com/ns/resin">  &lt;jms-connection-factory uri="resin:"/>  &lt;jms-queue name="my_queue" uri="memory:"/>  &lt;ejb-message-bean class="demo.MyListener">    &lt;destination>${my_queue}&lt;/destination>  &lt;/ejb-message-bean>&lt;/web-app></example><p>The <code>&lt;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>&lt;destination></code> tagspecifies the queue to use.</p><p>Because the <code>&lt;ejb-message-bean></code> is a Resin IoC bean, itcan use an optional <code>&lt;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">&lt;web-app xmlns="http://caucho.com/ns/resin">  &lt;resource-adapter class="org.apache.activemq.ra.ActiveMQResourceAdapter">    &lt;init server-url="vm://localhost"/>  &lt;/resource>  &lt;ejb-message-bean class="qa.MyListener">    &lt;activation-spec class="org.apache.activemq.ra.ActiveMQActivationSpec">      &lt;init physical-name="queue.test"/>    &lt;/activation-spec>  &lt;/ejb-message-bean>&lt;/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">&lt;web-app xmlns="http://caucho.com/ns/resin">  &lt;resource-adapter uri="activemq:">    &lt;init server-url="vm://localhost"/>  &lt;/resource>  &lt;ejb-message-bean class="qa.MyListener">    &lt;activation-spec uri="activemq:">      &lt;init physical-name="queue.test"/>    &lt;/activation-spec>  &lt;/ejb-message-bean>&lt;/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 + -