【问题标题】:Virtual topics work when using ActiveMQ 5.x's connection factory, but not Artemis' connection factory虚拟主题在使用 ActiveMQ 5.x 的连接工厂时有效,但不是 Artemis 的连接工厂
【发布时间】:2021-12-03 01:52:58
【问题描述】:

我正在将现有代码从使用 ActiveMQ 5.x 迁移到使用 Artemis。使用org.apache.activemq.ActiveMQConnectionFactory 时,我的虚拟主题消费者队列有发送到排队的虚拟主题的消息。当使用org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory 时,它们不会。

适用于使用 ActiveMQ 5.x 的连接工厂的虚拟主题的连接池配置是:

<bean id="jmsFactory" class="org.apache.activemq.jms.pool.PooledConnectionFactory" init-method="start" destroy-method="stop">
    <property name="connectionFactory">
        <bean class="org.apache.activemq.ActiveMQConnectionFactory">
            <property name="brokerURL" value="failover:${activemq.broker}" />
            <property name="userName"  value="${activemq.credentials.username}"/>
            <property name="password"  value="${activemq.credentials.password}"/>
        </bean>
    </property>
    <property name="maxConnections"                    value="${activemq.connectionPool.size}" />
    <property name="maximumActiveSessionPerConnection" value="${activemq.connectionPool.sessionsPerConnection}" />
</bean>

不适用于使用 Artemis 连接工厂的虚拟主题的连接池配置是:

<bean id="jmsConnectionFactory" class="org.apache.activemq.jms.pool.PooledConnectionFactory" init-method="start" destroy-method="stop">
    <property name="connectionFactory">
        <bean class="org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory">
            <constructor-arg name="url"      value="${activemq.broker}"/>
            <constructor-arg name="user"     value="${activemq.credentials.username}"/>
            <constructor-arg name="password" value="${activemq.credentials.password}"/>
        </bean>
    </property>
    <property name="maxConnections"                    value="${activemq.connectionPool.size}" />
    <property name="maximumActiveSessionPerConnection" value="${activemq.connectionPool.sessionsPerConnection}" />
</bean>

对于虚拟主题,我的消费者是 Camel 路由,生产者是 Spring 的 JmsTemplate 类的实例。生产者配置为以模式VirtualTopic.Foo 生产主题,消费者配置为从模式jms:queue:VirtualTopic.Foo::Consumer.MyApplication.VirtualTopic.Foo 中的Camel 端点消费。 jms Camel 组件配置了上面的 jmsFactory bean,JmsTemplate 实例也是如此:

<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
    <property name="connectionFactory"  ref="jmsFactory"/>
    <property name="deliveryPersistent" value="${activemq.delivery.persistent}"/>
</bean>

理想情况下,我可以使用 Artemis 的ActiveMQConnectionFactory。是什么导致发送到虚拟主题的消息在使用时没有被分派到消费者队列?

【问题讨论】:

  • 为什么不继续使用org.apache.activemq.ActiveMQConnectionFactory,因为它有效?切换到org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory的目的是什么?
  • @JustinBertram 随着升级,我不得不从使用代理统计插件转换为对 activemq.management 队列执行操作,如果执行操作的连接不是使用 Artemis 创建的,则会引发验证错误' 连接工厂。出于这个原因,我目前使用两个连接工厂配置并在需要时注入连接池,但我想通过只有一个连接池来简化配置。
  • 从 OpenWire 连接使用 activemq.management 时遇到什么“验证错误”?我希望这能奏效。
  • @JustinBertram 在Spring的JmsTemplate.sendAndReceive中使用JMSManagementHelper.putOperationInvocation时出现错误:java.lang.IllegalArgumentException: Cannot send a foreign message as a management message org.apache.activemq.command.ActiveMQMessageorg.apache.activemq.artemis.api.jms.management.JMSManagementHelper.getCoreMessage(JMSManagementHelper.java:33) ~[artemis-jms-client-2.16.0.jar:2.16.0]
  • 很高兴知道!我手动形成了activemq.management 消息并收到了响应;我将在稍后解析响应 JSON。我还将尝试使用jms 而不是activemq,并尽可能报告结果。感谢您的帮助。

标签: java spring apache-camel activemq-artemis


【解决方案1】:

这可能与所使用的 JMS 驱动程序有任何关系,也可能没有任何关系。虚拟主题及其消费者的创建方式和时间似乎是个问题。下面详细说明我是如何实现这一点的,但简而言之,请确保在创建消费者之前创建虚拟主题。


我注意到我的一个虚拟主题 VirtualTopic.Fig 正在运行,但我的其他虚拟主题都没有。虚拟主题的所有消费者队列都是使用完全限定的队列名称创建的,如Artemis documentation 中所述(订阅队列VirtualTopic.Fig::Consumer.A.VirtualTopic.Fig 而不是Consumer.A.VirtualTopic.Fig)。我运行了listAddresses 管理命令并看到了虚拟主题的输出:

name                        size    consumers      anycast    multicast 
-----------------------------------------------------------------------
VirtualTopic.Apple             -            1            Y            -
VirtualTopic.Banana            -            1            Y            -
VirtualTopic.Cantaloupe        -            1            Y            -
VirtualTopic.DragonFruit       -            1            Y            -
VirtualTopic.ElderBerry        -            1            Y            -
VirtualTopic.Fig               -            1            Y            Y
-----------------------------------------------------------------------

使用updateAddress 命令(updateAddress VirtualTopic.DragonFruit ANYCAST,MULTICAST),我更新了VirtualTopic.DragonFruit 以拥有多播路由,重新启动了我的消费者,其中大多数开始接收消息。假设剩余的消费者没有工作,因为它们是在主题创建之前创建的,并且绑定到地址的任播版本,对于每个地址,我:

  1. 关闭所有从虚拟主题生成或使用的应用程序。
  2. 使用destroyQueue 命令 (destroyQueue Consumer.A.VirtualTopic.DragonFruit true true) 销毁消费者队列。
  3. 使用deleteAddress 命令 (deleteAddress VirtualTopic.DragonFruit) 删除主题。
  4. 使用createAddress 命令 (createAddress VirtualTopic.DragonFruit MULTICAST) 将主题创建为多播地址。
  5. 重新启动所有应用程序。

手动创建虚拟主题后,一切都开始工作了。 listAddresses 命令的新输出是:

name                        size    consumers      anycast    multicast 
-----------------------------------------------------------------------
VirtualTopic.Apple             -            1            -            Y
VirtualTopic.Banana            -            1            -            Y
VirtualTopic.Cantaloupe        -            1            -            Y
VirtualTopic.DragonFruit       -            1            -            Y
VirtualTopic.ElderBerry        -            1            -            Y
VirtualTopic.Fig               -            1            -            Y
-----------------------------------------------------------------------

listQueues 命令的输出显示消费者现在正在接收消息:

name                                   size    consumers     enqueued     dequeued 
----------------------------------------------------------------------------------
Consumer.A.VirtualTopic.Apple             0            1           88           88
Consumer.A.VirtualTopic.Banana            0            1            4            4
Consumer.A.VirtualTopic.Cantaloupe        0            1           12           12
Consumer.A.VirtualTopic.DragonFruit       0            1           74           74
Consumer.A.VirtualTopic.ElderBerry        0            1         1776         1776
Consumer.A.VirtualTopic.Fig               0            1           75           75
----------------------------------------------------------------------------------

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-27
    • 1970-01-01
    • 2017-12-08
    • 2018-08-10
    • 2018-02-03
    • 2017-03-13
    相关资源
    最近更新 更多