如何在JBoss中配置ActiveMQ JCA连接器以使用XA连接? [英] How to configure ActiveMQ JCA connector in JBoss to use XA connections?

查看:145
本文介绍了如何在JBoss中配置ActiveMQ JCA连接器以使用XA连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在JBoss 5.1.0上,我使用* -ds.xml(标准jboss DS)配置了Datasource(PostgreSQL 8.3.11)。它使用XADataSource( PGXADataSource )。我也有ActiveMQ代理(现在它在VM中运行,在JBoss下,但它将在不同的服务器上运行)。

On JBoss 5.1.0 I have Datasource (PostgreSQL 8.3.11) configured using *-ds.xml (standard jboss DS). It uses XADataSource (PGXADataSource). I also have ActiveMQ broker (right now it runs as in-VM, under JBoss, but it will be on separate server latter).

我想做的是使ActiveMQ连接工厂和数据源参与XA事务。例如,我想更新DB记录并将UMS消息作为UOW发送。你明白了。

What I want to do is to make ActiveMQ Connection Factory and Datasource to participate in XA Transactions. For example, I want to update DB record and send a JMS message as a UOW. You get the idea.

我在my-pg-ds.xml中配置了PGXADataSource并且它可以工作(我可以跟踪执行到 PGXAConnection的启动方法)。我试图配置 ActiveMQXAConnectionFactory 直接在Spring中(我使用的是Spring 3.0.2.RELEASE),但这不起作用,因为在这种情况下是Spring事务管理器(我使用注释让Spring配置 JtaTransactionManager ,它简单地将所有工作委托给Jboss事务管理器)没有为给定的 ActiveMQXAConnection 。每当我尝试发送消息时,我都会收到异常JMSException,说Session的XAResource尚未在分布式事务中登记。抛出 ActiveMQXASession

I configured PGXADataSource in my-pg-ds.xml and it works (I can trace execution all the way to PGXAConnection's start method). I have tried to configure ActiveMQXAConnectionFactory directly in Spring (I am using Spring 3.0.2.RELEASE), but this does not work, because in this case Spring transaction manager (I use annotation to let Spring configure JtaTransactionManager which simply delegates all the work to Jboss transaction manager) does not enlist XAResource for given ActiveMQXAConnection. Whenever I try to send a message I get an exception JMSException saying "Session's XAResource has not been enlisted in a distributed transaction." thrown from ActiveMQXASession.

由于这不起作用,我已切换到ActiveMQ ConnectionFactory的JCA配置(基于这个文档),它适用于常规 ConnectionFactory ,但我不明白如何配置它以使用XAConnectionFactory。似乎资源适配器根本没有适当的ManagedConnectionFactory XA连接工厂的ManagedConnection等实现。

Since that did not work, I have switched to JCA configuration of ActiveMQ ConnectionFactory (based on this document) and it works for regular ConnectionFactory, but I do not understand how can I configure it to use XAConnectionFactory. It seems like Resource Adapter simply does not have proper ManagedConnectionFactory, ManagedConnection, etc. implementations for XA connection factory.

我是否遗漏了某些东西,或者我别无选择,只能为资源适配器编写XA包装器?

Am I missing something or do I have no choice but to write XA wrappers for resource adapter?

推荐答案

好的,我找到了解决方案。 Jboss包含任何JMS工厂的JCA连接器(支持两种类型的事务:XA和本地)。它位于/server//deploy/jms-ra.rar。以下是我配置它的方法。

Ok, I found the solution. Jboss includes JCA connector for any JMS factory (supports both types of transactions: XA and local). It is located in /server//deploy/jms-ra.rar. Here is how I configured it.

首先, activemq-jms-ds.xml 进入部署目录的文件jms-ra.rar旁边:

First, activemq-jms-ds.xml file that goes into deploy directory next to jms-ra.rar:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE connection-factories
    PUBLIC "-//JBoss//DTD JBOSS JCA Config 1.5//EN"
    "http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd">

<connection-factories>
    <mbean code="org.jboss.jms.jndi.JMSProviderLoader"
       name="jboss.messaging:service=JMSProviderLoader,name=ActiveMQJMSProvider">
        <attribute name="ProviderName">ActiveMQJMSProvider</attribute>
        <attribute name="ProviderAdapterClass">org.jboss.jms.jndi.JNDIProviderAdapter</attribute>
        <attribute name="FactoryRef">java:/activemq/XAConnectionFactory</attribute>
        <attribute name="QueueFactoryRef">java:/activemq/XAConnectionFactory</attribute>
        <attribute name="TopicFactoryRef">java:/activemq/XAConnectionFactory</attribute>
    </mbean>

    <tx-connection-factory>
        <jndi-name>JmsXAConnectionFactory</jndi-name>
        <xa-transaction/>
        <rar-name>jms-ra.rar</rar-name>
        <connection-definition>org.jboss.resource.adapter.jms.JmsConnectionFactory</connection-definition>
        <config-property name="JmsProviderAdapterJNDI" type="java.lang.String">java:/ActiveMQJMSProvider</config-property>
    </tx-connection-factory>
</connection-factories>

这告诉Jboss调查jms-ra.rar并找到可以提供托管连接工厂的适配器 org.jboss.resource.adapter.jms.JmsConnectionFactory 。内部jms适配器依赖于JmsProviderAdapter,它用于存储连接工厂的JNDI名称(在我的配置中所有名称都相同)。

This tells Jboss to look into jms-ra.rar and find adapter that can provide managed connection factory for org.jboss.resource.adapter.jms.JmsConnectionFactory. Internally jms adapter depends on JmsProviderAdapter, which is used to store JNDI names of connection factories (in my config all names are the same).

我使用mbean标签配置JMSProviderLoader (这是从内部JBoss配置中复制的)。现在,我所要做的就是以某种方式创建我的XA连接工厂的实例并将其绑定到 java:/ activemq / XAConnectionFactory 。有几种方法可以做到这一点(例如,实现MBean包装器)。

I use mbean tag to configure JMSProviderLoader (this is copied from one of internal JBoss configs). Now, all I have to do is somehow create an instance of my XA connection factory and bind it to java:/activemq/XAConnectionFactory. There are several ways to do it (implement MBean wrapper, for example).

由于我是Jboss 5,我使用了微容器(这可能适用于Jboss 6)。我将 activemq-jms-jboss-beans.xml 文件添加到部署者 direcotry:

Since I am Jboss 5 I used microcontainer (which is likely to work in Jboss 6). I added activemq-jms-jboss-beans.xml file into deployersdirecotry:

<?xml version="1.0" encoding="UTF-8"?>
<deployment xmlns="urn:jboss:bean-deployer:2.0">
    <!-- Define a Jndi binding aspect/annotation that exposes beans via jndi
        when they are registered with the kernel.
    -->
    <aop:lifecycle-configure xmlns:aop="urn:jboss:aop-beans:1.0"
        name="DependencyAdvice"
        class="org.jboss.aop.microcontainer.aspects.jndi.JndiLifecycleCallback"
        classes="@org.jboss.aop.microcontainer.aspects.jndi.JndiBinding"
        manager-bean="AspectManager"
        manager-property="aspectManager">
    </aop:lifecycle-configure>

    <bean name="ActiveMQXAConnectionFactory" class="org.apache.activemq.ActiveMQXAConnectionFactory">
        <annotation>@org.jboss.aop.microcontainer.aspects.jndi.JndiBinding(name="activemq/XAConnectionFactory", aliases={"java:/activemq/XAConnectionFactory"})</annotation>
        <property name="brokerURL">vm://localhost</property>
    </bean>
</deployment>

我创建了一个 ActiveMQXAConnectionFactory bean。为了将它绑定到JNDI,我使用JndiBinding注释对其进行注释。要使此注释起作用,我们需要JndiLifecycleCallback。据我所知,JidiLifecycleCallback在由微容器创建的每个bean上调用,并检查该bean上的JndiBinding注释。

I create a ActiveMQXAConnectionFactory bean. To bind it to JNDI, I annotate it with JndiBinding annotation. For this annotation to work, we need JndiLifecycleCallback. As far as I can tell, JndiLifecycleCallback is called on every bean created by microcontainer and checks for JndiBinding annotation on that bean.

这篇关于如何在JBoss中配置ActiveMQ JCA连接器以使用XA连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆