Jboss EAP 6.4集成Artemis 2.17后MDB无法监听队列问题咨询
问题根因
- Artemis RA默认会优先从JNDI查找MDB配置的目的地,你当前MDB的
destination属性配置的是队列物理名TestQueue,而非你在standalone.xml中配置的队列JNDI名,因此触发JNDI查找失败的警告,RA会自行创建队列对象。 - 你使用的
amq-user没有在Artemis服务端创建队列的权限,或Artemis服务端未开启自动创建队列的配置,导致RA向服务端发起队列创建请求时被拒绝,触发QUEUE_DOES_NOT_EXIST报错。 - 你可以发送消息是因为Artemis默认开启了自动创建地址的配置,但消费消息必须绑定对应的队列,队列不会随着地址自动创建。
解决方案
方案1:MDB直接使用物理队列名(推荐)
在MDB的激活配置中新增两个参数,禁用JNDI查找并开启自动创建队列:
@MessageDriven(mappedName = "java:jboss/jms/queue/TestQueue", activationConfig = { @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), @ActivationConfigProperty(propertyName = "destination", propertyValue = "TestQueue"), @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"), // 新增以下两个配置 @ActivationConfigProperty(propertyName = "useJNDI", propertyValue = "false"), @ActivationConfigProperty(propertyName = "autoCreateQueues", propertyValue = "true") }) public class TestQueueListener implements MessageListener {}
同时在Artemis服务端的权限配置中,给amq-user分配对应地址的createQueue、consume权限即可。
方案2:MDB使用JNDI查找已配置的队列
将MDB的destination属性值替换为你在standalone.xml中配置的队列JNDI名:
@ActivationConfigProperty(propertyName = "destination", propertyValue = "java:jboss/jms/queue/TestQueue")
同时提前在Artemis服务端手动创建名为TestQueue的队列,或在resource-adapter全局配置中添加自动创建队列参数:
<config-property name="autoCreateQueues">true</config-property>
内容的提问来源于stack exchange,提问作者java_dev_1234
相关产品推荐
相关产品推荐

