【发布时间】: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