ActiveMQ

From Resin 3.0

(Difference between revisions)
Jump to: navigation, search
Line 1: Line 1:
 +
== JCA ==
 +
 
ActiveMQ can be configured in Resin using ActiveMQ's JCA adapter.  The .rar file is in apache-activemq-5.0.0/lib/options/activemq-rar-5.0.0.rar
 
ActiveMQ can be configured in Resin using ActiveMQ's JCA adapter.  The .rar file is in apache-activemq-5.0.0/lib/options/activemq-rar-5.0.0.rar
  
 
In the resin.conf, you'll need to add a <resource-deploy> tag to tell Resin where to look for resources:
 
In the resin.conf, you'll need to add a <resource-deploy> tag to tell Resin where to look for resources:
 
+
<code><pre>
 
   <resin xmlns="http://caucho.com/ns/resin">
 
   <resin xmlns="http://caucho.com/ns/resin">
 
     <cluster id="">
 
     <cluster id="">
Line 11: Line 13:
 
     </cluster>
 
     </cluster>
 
   </resin>
 
   </resin>
 +
</pre></code>
  
 
Then, in your resin-web.xml, you'll need to configure the connector.  It will look like:
 
Then, in your resin-web.xml, you'll need to configure the connector.  It will look like:
 
+
<code><pre>
 
   <web-app xmlns="http://caucho.com/ns/resin">
 
   <web-app xmlns="http://caucho.com/ns/resin">
 
      
 
      
     <connector class="org.apache.activemq.ra.ActiveMQResourceAdapter">
+
     <resource-adapter uri="activemq:">
        <init>
+
        <init server-url="vm://localhost"/>
            <ServerUrl>vm://localhost</ServerUrl>
+
    </resource-adapter>
        </init>
+
 
   
+
    <connection-factory uri="activemq:" name="activemq"/>
        <connection-factory class="javax.jms.QueueConnectionFactory"/>
+
 
   
 
   
        <bean class="javax.jms.Queue">
+
    <jms-queue uri="activemq:" name="test">
            <init PhysicalName="queue.test"/>
+
        <init physical-name="queue.test"/>
        </bean>
+
    </jms-queue>
    </connector>
+
 
   </web-app>
 
   </web-app>
 +
</pre></code>
  
* The <connector> configures a JCA connector.   
+
* The <resource-adapter> configures a JCA resource-adapter.   
* The connector class is the resource adapter class.   
+
* The uri="activemq:" is an alias for class="org.apache.activemq.ra.ActiveMQResourceAdapter" (contained in resin-support.jar)  
 
* The <init> block configures the resource adapter parameters.
 
* The <init> block configures the resource adapter parameters.
 
* The <connection-factory> configures the outbound factory
 
* The <connection-factory> configures the outbound factory
 
* The <bean> configures the Queue (i.e. the adminobject)
 
* The <bean> configures the Queue (i.e. the adminobject)
 +
 +
<code><pre>
 +
package demo;
 +
 +
import javax.jms.*;
 +
import javax.servlet.*;
 +
import javax.webbeans.*;
 +
 +
public class DemoServlet extends GenericServlet {
 +
  @In ConnectionFactory _factory;
 +
  @Named("test") Queue _queue;
 +
 +
  public void service(...)
 +
  {
 +
    ...
 +
    Connection conn = _factory.createConnection();
 +
    Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
 +
    session.send(_queue, session.createTextMessage("test"));
 +
    ...
 +
  }
 +
}
 +
</pre></code>

Revision as of 21:32, 27 January 2008

JCA

ActiveMQ can be configured in Resin using ActiveMQ's JCA adapter. The .rar file is in apache-activemq-5.0.0/lib/options/activemq-rar-5.0.0.rar

In the resin.conf, you'll need to add a <resource-deploy> tag to tell Resin where to look for resources:

  <resin xmlns="http://caucho.com/ns/resin">
    <cluster id="">
        <host id="">
           <resource-deploy path="deploy"/>
            ...
         </host>
     </cluster>
  </resin>

Then, in your resin-web.xml, you'll need to configure the connector. It will look like:

  <web-app xmlns="http://caucho.com/ns/resin">
    
     <resource-adapter uri="activemq:">
        <init server-url="vm://localhost"/>
     </resource-adapter>

     <connection-factory uri="activemq:" name="activemq"/>
 
     <jms-queue uri="activemq:" name="test">
         <init physical-name="queue.test"/>
     </jms-queue>
  </web-app>
  • The <resource-adapter> configures a JCA resource-adapter.
  • The uri="activemq:" is an alias for class="org.apache.activemq.ra.ActiveMQResourceAdapter" (contained in resin-support.jar)
  • The <init> block configures the resource adapter parameters.
  • The <connection-factory> configures the outbound factory
  • The <bean> configures the Queue (i.e. the adminobject)
package demo;

import javax.jms.*;
import javax.servlet.*;
import javax.webbeans.*;

public class DemoServlet extends GenericServlet {
  @In ConnectionFactory _factory;
  @Named("test") Queue _queue;

  public void service(...)
  {
    ...
    Connection conn = _factory.createConnection();
    Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    session.send(_queue, session.createTextMessage("test"));
    ...
  }
}
Personal tools