Apache ActiveMQ Artemis 客户端可以连接到现有的 ActiveMQ Classic 5.15.x 代理吗?

问题描述 投票:0回答:2

ActiveMQ Classic 5.15.3 不支持 JMS 2.0 API。大多数开发人员建议项目如果需要 JMS 2.0 客户端支持,则使用 ActiveMQ Artemis。 ActiveMQ Artemis 客户端可以连接到 ActiveMQ Classic 代理吗?

java jms activemq activemq-artemis
2个回答
4
投票

不可以,Artemis JMS 客户端使用 ActiveMQ 5.x 代理无法理解的 Artemis Core 协议,因此您无法使用该客户端连接到它。即使您可以,也不会启用任何 JMS 2.0 功能,因为代理需要支持共享订阅等 2.0 功能。

根据您想要执行的操作,您很有可能仍然可以通过 JMS 1.1 API 使用 ActiveMQ JMS 客户端来完成此操作,例如使用虚拟主题来实现共享样式订阅行为。

Artemis Broker 确实了解 OpenWire 协议,因此您可以使用相同的 ActiveMQ 5.x JMS 客户端连接到两者,但该客户端仅限于 JMS 1.1 API。

两个代理也都支持 AMQP 1.0,因此 Qpid JMS AMQP 1.0 客户端将能够与任一代理通信。 Qpid-JMS 是基于 JMS 2.0 的客户端,因此 2.0 的功能(如共享订阅)不适用于 ActiveMQ 5.x,但 2.0 的一些其他语法糖类型 API(如基于 JMSContext 的位)大部分都可以工作。


1
投票

正如 Tim 所说,不支持 Artemis 客户端。但是,如果您使用 QPid 客户端和 AMQP 1.0 协议,则至少 JMS 2.0 API 的某些部分*可以工作。

例如,以下代码可将消息发送到 ActiveMQ 5.15

Hashtable<String,Object> properties = new Hashtable<>();
    properties.put("connectionfactory.connectionFactory","amqp://localhost:5672");
    properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.qpid.jms.jndi.JmsInitialContextFactory");
    Context jndiContext = new InitialContext(properties);
    ConnectionFactory connectionFactory
            = (ConnectionFactory) jndiContext.lookup("connectionFactory");

    try (JMSContext context = connectionFactory.createContext();) {
        context.createProducer().send(context.createQueue("QueueX"),"Hello World" );
    }

使用 qpid-jms-client 0.29。

您还需要使用

transport.transformer=jms
配置 ActiveMQ 中的 amqp 连接器。

*)我还没有尝试所有功能,例如共享订阅者等,因为经纪人可能会也可能不会遇到这些问题。

© www.soinside.com 2019 - 2024. All rights reserved.