gpt4 book ai didi

jakarta-ee - 如何配置 Wildfly 连接到 RabbitMQ?

转载 作者:行者123 更新时间:2023-12-04 01:07:38 27 4
gpt4 key购买 nike

我很难将 JB EAP7 配置为使用 RabbitMQ 作为消息代理。
我创建了一个 rabbitmq 模块并将其定义为我的standalone-ha.xml 中的一个全局模块。

模块/系统/层/base/com/rabbitmq/main/module.xml:

<module xmlns="urn:jboss:module:1.1" name="com.rabbitmq">
<resources>
<resource-root path="rabbitmq-jms-1.7.0.jar"/>
<resource-root path="amqp-client-4.2.0.jar" />
</resources>
<dependencies>
<module name="javax.api" />
<module name="javax.transaction.api"/>
<module name="org.slf4j"/>
</dependencies>
</module>

JB7 启动没有问题。但我在 server.log 中看到以下内容,表明 MDB 正在尝试绑定(bind)到 ActiveMQ 连接(我猜是 Wildfly 中的默认提供程序):
2017-08-29 17:24:09,193 INFO  [org.jboss.as.ejb3]WFLYEJB0042: Started message driven bean 'Subscriber' with 'activemq-ra' resource adapter
2017-08-29 17:24:09,368 INFO [javax.enterprise.resource.webcontainer.jsf.config]Initializing Mojarra 2.2.12-jbossorg-2 for context '/webapp-0.0.1-SNAPSHOT'
2017-08-29 17:24:09,462 INFO [org.apache.activemq.artemis.ra]AMQ151000: awaiting topic/queue creation java:/global/mq/kodo
2017-08-29 17:24:10,103 INFO [org.wildfly.extension.undertow]WFLYUT0021: Registered web context: /webapp-0.0.1-SNAPSHOT
2017-08-29 17:24:10,285 INFO [org.jboss.as.server]WFLYSRV0010: Deployed "webapp-0.0.1-SNAPSHOT.war" (runtime-name : "webapp-0.0.1-SNAPSHOT.war")
2017-08-29 17:24:10,286 INFO [org.jboss.as.server]WFLYSRV0010: Deployed "kodo-jdo.rar" (runtime-name : "kodo-jdo.rar")
2017-08-29 17:24:11,465 INFO [org.apache.activemq.artemis.ra]AMQ151001: Attempting to reconnect org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec(ra=org.apache.activemq.artemis.ra.ActiveMQResourceAdapter@78712571 destination=java:/global/mq/kodo destinationType=javax.jms.Queue ack=Auto-acknowledge durable=false clientID=null user=null maxSession=15)

我不确定如何在我的 MDB 中识别我希望 MDB 使用我的 RabbitMQ 定义的 ConnectionFactory。我的 MDB 定义为:
@MessageDriven(
activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "java:/global/mq/kodo") })
public class Subscriber implements MessageListener {

public void onMessage(final Message message) {
try {
System.out.println(message.getBody(Object.class).toString());
} catch (JMSException e) {
// TODO Auto-generated catch block
throw new RuntimeException(e);
}
}
}

但我找不到在哪里/如何指定 ConnectionFactory 的文档。我试过添加 @JMSConnectionFactory( String JNDI)注释到我的类(class),我仍然得到相同的结果。

我的 RabbitMQ 模块定义中是否缺少某些内容?我的 MDB 没有正确注释吗?为了配置我的 MDB 以使用我的 RabbitMQ ConnectionFactory 连接到 Message Broker,我需要做什么?

最佳答案

如果您想为 MDB 使用另一个代理,您必须更改 Wildfly 配置文件中的配置,该配置文件仅存在于完整配置文件中,因为 MDB 是 Java EE 完整配置文件的一部分,而不是 Web 配置文件的一部分。
例如,此配置在standalone-full.xml 文件中可用:

<mdb>
<resource-adapter-ref resource-adapter-name="${ejb.resource-adapter-name:activemq-ra.rar}"/>
<bean-instance-pool-ref pool-name="mdb-strict-max-pool"/>
</mdb>

不幸的是,似乎还不能使用 MDB 通过 RabbitMQ JMS Client 连接到 RabbitMQ。 .
这是因为其中没有实现一些可选的 JMS 客户端规范特性。见 RabbitMQ Jms client compliance page

因此,要使用连接到 RabbitMQ 的消息监听器(如果您不想轮询队列),您可以尝试在 setMessageListener 的帮助下手动声明它们。方法和 CDI。见 this answer详情。但是我不确定最后一个是否真的可以在 Wildfly 中工作(将在 Wildfly 中从 Java EE Web Profile 开始测试),根据 javadoc,此方法会引发异常:

if the JMS provider fails to set the MessageConsumer's MessageListener for one of the following reasons: an internal error has occurred or this method has been called in a Java EE web or EJB application (though it is not guaranteed that an exception is thrown in this case)



请注意,要使用 RabbitMQ JMS Client 中描述的 Wildfly 配置文档,您必须使用 1.7.0 版本,如 this Pull request启用 Wildfly 配置。

我将尝试分享我在测试 RabbitMQ JMS 客户端集成到 wildfly 时所做的一段代码

关于jakarta-ee - 如何配置 Wildfly 连接到 RabbitMQ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45950987/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com