WildFly 10 Artemis和ActiveMQ 5.14之间的JMS桥接(ONCE_AND_ONLY_ONCE服务质量)

时间:2016-09-15 10:36:06

标签: jms activemq wildfly wildfly-10 activemq-artemis

我正在尝试在Artemis(在WildFly 10中运行)和ActiveMQ 5.14之间建立一个JMS桥

一般来说,这个过程看起来运行顺利,但不幸的是我陷入了使ONCE_AND_ONLY_ONCE QoS工作所必需的XA配置。

虽然消息确实到达ActiveMQ端,但我在WildFly日志中收到以下错误:

11:25:57,920 WARN  [org.apache.activemq.artemis.jms.bridge] (Thread-97) AMQ342009: JMS Bridge failed to send + acknowledge batch, closing JMS objects: javax.jms.IllegalStateException: Not a transacted session
at org.apache.activemq.ActiveMQSession.commit(ActiveMQSession.java:577)
at org.apache.activemq.ra.ManagedSessionProxy.commit(ManagedSessionProxy.java:108)
at org.apache.activemq.artemis.jms.bridge.impl.JMSBridgeImpl.sendBatchNonTransacted(JMSBridgeImpl.java:1291)
at org.apache.activemq.artemis.jms.bridge.impl.JMSBridgeImpl.sendBatch(JMSBridgeImpl.java:1251)
at org.apache.activemq.artemis.jms.bridge.impl.JMSBridgeImpl.access$1500(JMSBridgeImpl.java:75)
at org.apache.activemq.artemis.jms.bridge.impl.JMSBridgeImpl$BatchTimeChecker.run(JMSBridgeImpl.java:1794)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

我的问题类似于这个问题(Wildfly 10 ONCE_AND_ONLY_ONCE JMS网桥),但遗憾的是该解决方案并不完全适用于我的情况,因为我的目标是ActiveMQ 5.14。

从我看过的所有帖子中我都应该确保应该为XA支持配置桥两端的连接工厂。在Artemis方面,这看起来很简单:只需将factory-type =“XA_GENERIC”添加到定义中。但是,我无法弄清楚如何在ActiveMQ方面做到这一点。

以下是我的standalone-full.xml中指定我的消息传递子系统的片段:

    <subsystem xmlns="urn:jboss:domain:messaging-activemq:1.0">
        <server name="default">
            <security-setting name="#">
                <role name="guest" delete-non-durable-queue="true" create-non-durable-queue="true" consume="true" send="true"/>
            </security-setting>
            <address-setting name="#" message-counter-history-day-limit="10" page-size-bytes="2097152" max-size-bytes="10485760" expiry-address="jms.queue.ExpiryQueue" dead-letter-address="jms.queue.DLQ"/>
            <http-connector name="http-connector" endpoint="http-acceptor" socket-binding="http"/>
            <http-connector name="http-connector-throughput" endpoint="http-acceptor-throughput" socket-binding="http">
                <param name="batch-delay" value="50"/>
            </http-connector>
            <in-vm-connector name="in-vm" server-id="0"/>
            <http-acceptor name="http-acceptor" http-listener="default"/>
            <http-acceptor name="http-acceptor-throughput" http-listener="default">
                <param name="batch-delay" value="50"/>
                <param name="direct-deliver" value="false"/>
            </http-acceptor>
            <in-vm-acceptor name="in-vm" server-id="0"/>
            <jms-queue name="ExpiryQueue" entries="java:/jms/queue/ExpiryQueue"/>
            <jms-queue name="DLQ" entries="java:/jms/queue/DLQ"/>
            <jms-queue name="NonBridgedTestQueue" entries="java:jboss/exported/jms/queue/nonBridgedTestQueue"/>
            <jms-queue name="BridgedTestQueue" entries="java:jboss/exported/jms/queue/bridgedTestQueue"/>
            <connection-factory name="InVmConnectionFactory" entries="java:/ConnectionFactory" connectors="in-vm"/>
            <connection-factory name="RemoteConnectionFactory" entries="java:jboss/exported/jms/RemoteConnectionFactory" connectors="http-connector"/>
            <connection-factory name="InVmXAConnectionFactory" factory-type="XA_GENERIC" entries="java:/XAConnectionFactory" connectors="in-vm"/>               
            <pooled-connection-factory name="activemq-ra" transaction="xa" entries="java:/JmsXA java:jboss/DefaultJMSConnectionFactory" connectors="in-vm"/>
        </server>
        <jms-bridge name="simple-jms-bridge" add-messageID-in-header="true" max-batch-time="100" max-batch-size="10" max-retries="5" failure-retry-interval="10000" quality-of-service="ONCE_AND_ONLY_ONCE">
            <source destination="jboss/exported/jms/queue/bridgedTestQueue" connection-factory="java:/XAConnectionFactory"/>
            <target destination="jboss/activemq/queue/bridgedTestQueue" connection-factory="AMQConnectionFactory"/>
        </jms-bridge>
    </subsystem>

对于ActiveMQ定义,我使用了资源适配器,定义如下:

    <subsystem xmlns="urn:jboss:domain:resource-adapters:4.0">
        <resource-adapters>
            <resource-adapter id="activemq">
                <archive>activemq-rar-5.14.0.rar</archive>
                <transaction-support>XATransaction</transaction-support>
                <config-property name="ServerUrl">tcp://localhost:61616?jms.rmIdFromConnectionId=true</config-property>
                <config-property name="UserName">admin</config-property>
                <config-property name="UseInboundSession">false</config-property>
                <config-property name="Password">admin</config-property>
                <connection-definitions>
                    <connection-definition class-name="org.apache.activemq.ra.ActiveMQManagedConnectionFactory" jndi-name="java:/AMQConnectionFactory" enabled="true" pool-name="AMQConnectionFactory">
                        <xa-pool>
                            <min-pool-size>1</min-pool-size>
                            <max-pool-size>20</max-pool-size>
                            <prefill>false</prefill>
                            <is-same-rm-override>false</is-same-rm-override>
                        </xa-pool>
                    </connection-definition>
                </connection-definitions>
                <admin-objects>
                    <admin-object class-name="org.apache.activemq.command.ActiveMQTopic" jndi-name="java:jboss/activemq/topic/TestTopic" use-java-context="true" pool-name="TestTopic">
                        <config-property name="PhysicalName">
                            activemq/topic/TestTopic
                        </config-property>
                    </admin-object>
                    <admin-object class-name="org.apache.activemq.command.ActiveMQQueue" jndi-name="java:jboss/activemq/queue/TestQueue" use-java-context="true" pool-name="TestQueue">
                        <config-property name="PhysicalName">
                            activemq/queue/TestQueue
                        </config-property>
                    </admin-object>
                    <admin-object class-name="org.apache.activemq.command.ActiveMQQueue" jndi-name="java:jboss/activemq/queue/bridgedTestQueue" use-java-context="true" pool-name="BridgedTestQueue">
                        <config-property name="PhysicalName">
                            activemq/queue/bridgedTestQueue
                        </config-property>
                    </admin-object>
                </admin-objects>
            </resource-adapter>
        </resource-adapters>
    </subsystem>

赞赏正确方向的一些指示

格雷格

1 个答案:

答案 0 :(得分:2)

在发布这个问题后,我尝试了一些似乎有用的东西。仍然有兴趣听听这是否是正确的方法。

在查看资源适配器中的ra.xml文件时,我注意到它提供了一个额外的连接工厂作为管理对象。所以我将以下内容添加到standalone-full.xml中的资源适配器定义:

                    <admin-object class-name="org.apache.activemq.ActiveMQXAConnectionFactory" jndi-name="java:jboss/activemq/activeMQXAConnectionFactory" use-java-context="true">
                        <config-property name="brokerURL">
                            tcp://localhost:61616?jms.rmIdFromConnectionId=true
                        </config-property>
                    </admin-object>

使用此连接工厂,我按如下方式更新了JMS Bridge:

        <jms-bridge name="simple-jms-bridge" add-messageID-in-header="true" max-batch-time="100" max-batch-size="10" max-retries="5" failure-retry-interval="10000" quality-of-service="ONCE_AND_ONLY_ONCE">
            <source destination="jboss/exported/jms/queue/bridgedTestQueue" connection-factory="java:/XAConnectionFactory"/>
            <target destination="jboss/activemq/queue/bridgedTestQueue" connection-factory="java:jboss/activemq/activeMQXAConnectionFactory"/>
        </jms-bridge>

现在一切似乎都运作良好。消息到达ActiveMQ端,我在WildFly日志中没有遇到任何问题。 Whoopwhoop