You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

通过配置修改复用ActiveMQ Classic代码连接ActiveMQ Artemis

能否复用ActiveMQ Classic代码连接ActiveMQ Artemis?

完全可以通过修改JBoss EAP的资源适配器配置,复用现有基于标准JMS API的代码连接ActiveMQ Artemis,无需改动业务代码。ActiveMQ Artemis兼容ActiveMQ Classic的OpenWire协议,现有代码的JMS调用逻辑可以直接保留。

需要修改的关键配置参数

1. 替换资源适配器核心依赖与连接工厂类

原配置使用的是ActiveMQ Classic的资源适配器,需要替换为ActiveMQ Artemis的对应组件:

  • 将资源适配器的module从org.apache.activemq改为org.apache.activemq.artemis
  • 将连接工厂的class-name从org.apache.activemq.ra.ActiveMQManagedConnectionFactory改为org.apache.activemq.artemis.ra.ActiveMQRAManagedConnectionFactory

2. 更新故障转移连接地址(ServerUrl)

Artemis支持Classic的failover: URL格式,只需将原2台Classic节点替换为3台Artemis节点,同时保留原有的故障转移参数:

<config-property name="ServerUrl">failover:(tcp://node1:61616,tcp://node2:61616,tcp://node3:61616)?randomize=false&amp;jms.watchTopicAdvisories=false&amp;timeout=3000</config-property>

注:若Artemis集群使用广播发现机制,也可改用discovery:(tcp://node1:61616)自动发现集群节点,但直接指定所有节点更适合固定拓扑的场景。

3. 调整重发策略相关参数

Artemis RA的重发参数与Classic略有差异,需替换对应配置:

  • 移除Classic专属的RedeliveryBackOffMultiplier、RedeliveryUseExponentialBackOff
  • 改用Artemis的RetryIntervalMultiplier(对应指数退避乘数)、RetryInterval(初始重试间隔)、MaxRetryInterval(最大重试间隔)
  • 将MaximumRedeliveries替换为Artemis的MaxSessionRedeliveries

4. 保留通用配置参数

UserName、Password、UseInboundSession以及连接池的min-pool-size、max-pool-size等参数可直接保留,无需修改(需确保Artemis服务器上的用户权限与原Classic一致)。

修改后的完整资源适配器配置示例

<subsystem xmlns="urn:jboss:domain:resource-adapters:6.0">
    <resource-adapters>
        <resource-adapter id="org.apache.activemq.artemis">
            <module slot="main" id="org.apache.activemq.artemis"/>
            <config-property name="RetryIntervalMultiplier">3</config-property>
            <config-property name="ServerUrl">failover:(tcp://node1:61616,tcp://node2:61616,tcp://node3:61616)?randomize=false&amp;jms.watchTopicAdvisories=false&amp;timeout=3000</config-property>
            <config-property name="RetryInterval">1000</config-property>
            <config-property name="MaxSessionRedeliveries">1</config-property>
            <config-property name="UserName">user</config-property>
            <config-property name="UseInboundSession">true</config-property>
            <config-property name="Password">password</config-property>
            <connection-definitions>
                <connection-definition class-name="org.apache.activemq.artemis.ra.ActiveMQRAManagedConnectionFactory" jndi-name="java:/ConnectionFactory" enabled="true" tracking="false" use-java-context="true" pool-name="ConnectionFactory">
                    <config-property name="UseInboundSession">false</config-property>
                    <pool>
                        <min-pool-size>4</min-pool-size>
                        <max-pool-size>256</max-pool-size>
                        <prefill>true</prefill>
                    </pool>
                    <timeout>
                        <blocking-timeout-millis>12000</blocking-timeout-millis>
                        <idle-timeout-minutes>5</idle-timeout-minutes>
                    </timeout>
                </connection-definition>
            </connection-definitions>
        </resource-adapter>
    </resource-adapters>
</subsystem>

代码部分无需修改

现有通过JNDI查找java:/ConnectionFactory并使用标准JMS API、Camel JMS组件的代码可以完全复用,因为Artemis的连接工厂实现了标准JMS接口,与Classic的API兼容。

内容的提问来源于stack exchange,提问作者Surjit Sen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 09:28:15