Resin JCA ActiveMQ How to

From Resin 4.0 Wiki

Jump to: navigation, search

Resin, ActiveMQ and JCA

ActiveMQ can be configured in Resin using ActiveMQ's JCA adapter.

You can get the ActiveMQ RAR file at:

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

  <resin xmlns="">
    <cluster id="">
        <host id="">
           <resource-deploy path="/somedir/that/has/jca-rar/files/deploy"/>

Then, in your resin-web.xml (under WEB-INF of your webapp), you'll need to configure the connector. It will look like:

<?xml version="1.0" encoding="UTF-8" ?>
<web-app xmlns="">

	<resource-adapter class="org.apache.activemq.ra.ActiveMQResourceAdapter">
		<init server-url="vm://localhost" />

            name="activemq" />

	<jms-queue class="org.apache.activemq.command.ActiveMQQueue" name="test">
		<init physical-name="queue.test" />

  • The <resource-adapter> configures a JCA resource-adapter.
  • The <init> block configures the resource adapter parameters. Refer to ActiveMQ or the ra.xml file of the expanded rar file to see what parameters you can configure.
  • The <connection-factory> configures the outbound factory
  • The <jms-queue> configures the Queue (i.e. the adminobject)
package com.example;


import javax.inject.Inject;
import javax.inject.Named;
import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

 * Servlet implementation class Sender
public class Sender extends HttpServlet {

	@Inject @Named("activemq")
	QueueConnectionFactory _factory;
	@Inject @Named("test")
	Queue _queue;

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		QueueConnection conn = null;
		QueueSession session = null;
		QueueSender sender = null;

		try {

			 conn = _factory.createQueueConnection();
			 session = conn.createQueueSession(false,
			sender = session.createSender(_queue);
			sender.send(_queue, session.createTextMessage("test"));

		} catch (JMSException e) {
			throw new ServletException(e);
		} finally {
			try {
			} catch (JMSException e) {
				throw new ServletException(e);


Personal tools