6.2. camel-jms
将 camel-jms、camel-sjms 和 camel-sjms2 端点连接到远程 AMQ 7 代理的方法有两种。
- 使用 pooled-connection-factory 配置 remote-connector,如 JBoss EAP 配置消息传递指南中的 配置 Artemis 资源适配器 以连接到 Red Hat JBoss AMQ 7 部分。
- 使用 connection-factory 配置 remote-connector,如下所述 使用 connection-factory 配置一个 remote-connector
第一个选项是首选的方法,因为它提供连接池和 XA 事务支持。
对于使用持久订阅者的消息传递场景,JBoss EAP 上的 Fuse 7.9 不支持 pooled-connection-factory 的消息传递场景,因为 swig 7 规格进行了限制。在这些情况下,首选配置一个标准的未池 connection-factory。
使用 connection-factory 配置一个 remote-connector
创建一个指向远程消息传递服务器的 outbound-socket-binding:
/socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=messaging-remote-throughput:add(host=localhost, port=61616)
/socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=messaging-remote-throughput:add(host=localhost, port=61616)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 创建一个 remote-connector,引用在第 1 步中创建的 outbound-socket-binding。
/subsystem=messaging-activemq/server=default/remote-connector=netty-remote-throughput:add(socket-binding=messaging-remote-throughput)
/subsystem=messaging-activemq/server=default/remote-connector=netty-remote-throughput:add(socket-binding=messaging-remote-throughput)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 创建一个 connection-factory 引用在第 2 步中创建的 remote-connector。
/subsystem=messaging-activemq/server=default/connection-factory=simple-remote-artemis-connection-factory:add(entries=[java:/jms/RemoteJms],connectors=[netty-remote-throughput])
/subsystem=messaging-activemq/server=default/connection-factory=simple-remote-artemis-connection-factory:add(entries=[java:/jms/RemoteJms],connectors=[netty-remote-throughput])
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
6.2.1. 消息传递代理和客户端 复制链接链接已复制到粘贴板!
摘要
Fuse 7.9 不附带默认的内部消息传递代理,但设计为与外部 JMS 代理接口。
JBoss EAP 上的 Fuse 7.9 使用 JBoss EAP 上配置消息传递 中详述的资源适配器来访问外部消息传递代理。
有关 JBoss EAP 上 Fuse 7.9 上可用于消息传递的外部代理、JCA 适配器和 Camel 组件组合的更多信息,请参阅 支持的配置。
有关使用 JMS 在 JBoss EAP 上使用 Fuse 连接到外部代理的更多信息,请参阅 第 6.2 节 “camel-jms”。
camel-jms quickstart
提供了一个快速入门,用于演示将 camel-jms 组件与 JBoss EAP 上的 Fuse 搭配使用,以生成和使用 JMS 消息。
在本快速入门中,Camel 路由使用来自 EAP_HOME/standalone/data/orders
的文件,并将其内容放在名为 OrdersQueue
的内存中 ActiveMQ Artemis 队列中。然后,另一个 Camel 路由会消耗 OrdersQueue
的内容,并将顺序排序到 EAP_HOME/standalone/data/orders/processed
中的独立国家目录中。
CLI 命令创建和删除 OrdersQueue
CLI 脚本时,负责在应用部署和取消部署时为您创建和删除 JMS OrdersQueue
。这些脚本位于 EAP_HOME/quickstarts/camel-jms/src/main/resources/cli
目录中。
先决条件
要运行此快速入门,您必须有一个 Fuse 7.9 的工作版本
您还必须按照使用 JBoss AMQ 进行远程 JMS 通信 中的说明来连接到外部 AMQ 7 代理。然后,您可以使用默认连接工厂注入连接工厂。
@Resource(mappedName = "java:jboss/RemoteJmsXA") ConnectionFactory connectionFactory;
@Resource(mappedName = "java:jboss/RemoteJmsXA")
ConnectionFactory connectionFactory;
设置快速入门
- 以单机模式启动 JBOSS EAP。
-
导航到
EAP_HOME/quickstarts/camel/camel-jms
-
输入
mvn clean install -Pdeploy'
以构建和部署快速入门。 - 浏览 http://localhost:8080/example-camel-jms
您应该会看到标题为 'Orders Received' 的页面。当我们向示例应用程序发送订单时,本页中将列出每个国家的订购列表。
运行快速启动
EAP_HOME/quickstarts/camel/camel-jms/src/main/resources
目录中有一些示例顺序 XML 文件。Camel 将每 5 秒随机选择一个文件,并将其复制到 EAP_HOME/standalone/data/orders
中以进行处理。
控制台将输出详细说明每个顺序所发生的消息。输出将如下所示:
JmsConsumer[OrdersQueue]) Sending order to the UK JmsConsumer[OrdersQueue]) Sending order to another country JmsConsumer[OrdersQueue]) Sending order to the US
JmsConsumer[OrdersQueue]) Sending order to the UK
JmsConsumer[OrdersQueue]) Sending order to another country
JmsConsumer[OrdersQueue]) Sending order to the US
使用这些文件后,您可以返回到 http://localhost:8080/example-camel-jms/orders。每个国家/地区接收的订购数应该已增加 1。
所有已处理的顺序将分成以下目的地:
EAP_HOME/standalone/data/orders/processed/uk EAP_HOME/standalone/data/orders/processed/us EAP_HOME/standalone/data/orders/processed/other
EAP_HOME/standalone/data/orders/processed/uk
EAP_HOME/standalone/data/orders/processed/us
EAP_HOME/standalone/data/orders/processed/other
取消部署
要取消部署示例,请导航到 EAP_HOME/quickstarts/camel/camel-jms
运行 mvn clean -Pdeploy
。