Apache ActiveMQ Artemis 客户端能否连接到现有的 ActiveMQ 代理 5.15.X?

Posted

技术标签:

【中文标题】Apache ActiveMQ Artemis 客户端能否连接到现有的 ActiveMQ 代理 5.15.X?【英文标题】:Can an Apache ActiveMQ Artemis client connect to an existing ActiveMQ broker 5.15.X? 【发布时间】:2018-07-26 15:32:39 【问题描述】:

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

【问题讨论】:

【参考方案1】:

不,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 的位)将主要工作。

【讨论】:

我有一个非常简单的用例,即定期向外部 JMS 代理发送消息。我希望利用更简单的 API 来做到这一点。关于协议,我认为两者都能够使用 Openwire 协议。 ActiveMQ 5.x 和 ActiveMQ Artemis 代理都支持 OpenWire 协议。然而,正如 Tim 所说,Artemis JMS 客户端使用 5.x 代理不支持的 Artemis 核心协议(即不是 OpenWire)。如果您希望能够使用同一客户端同时连接到 5.x 代理和 Artemis 代理,您可以使用 5.x OpenWire JMS 客户端。当然,这将限制您使用 JMS 1.1 API。【参考方案2】:

正如 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 配置 amqp 连接器 i ActiveMQ。

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

【讨论】:

以上是关于Apache ActiveMQ Artemis 客户端能否连接到现有的 ActiveMQ 代理 5.15.X?的主要内容,如果未能解决你的问题,请参考以下文章

Apache ActiveMQ Artemis简介

Apache ActiveMQ Artemis简介

activemq artemis关于 Apache.NMS.AMQP 使用注意事项。

Apache ActiveMQ Artemis 客户端能否连接到现有的 ActiveMQ 代理 5.15.X?

带有独立 ActiveMQ 的 Wildfly 上的 ActiveMQ Artemis

如何在 ActiveMQ Artemis 中调度消息