20.9.2. 创建 JMS 桥
JMS 桥消费源 JMS 队列或主题里的消息并发送到目标 JMS 队列或主题(通常位于不同的服务器上)。它可以用于桥接 任何 JMS 服务器间的消息,只要这些消息是兼容 JMS 1.1 的。源和目的 JMS 资源通过 JNDI 查找,用于 JNDI 查找的客户类必须捆绑在模块里。然后在 JMS 桥配置里声明模块名。
过程 20.2. 创建 JMS 桥
在源 JMS 消息服务器上配置桥
请使用源服务器提供的说明配置 JMS 桥。关于如何在 JBoss EAP 5.x 上配置 JMS 桥的例子,请参考《JBoss EAP 6 移植指南》里的 Create a JMS Bridge 章节。配置目的 JBoss EAP 6 服务器上的 JMS 桥
在 JBoss EAP 6.1 以后的版本里,JMS 桥可以用于从任何兼容 JMS 1.1 的服务器上桥接消息。因为源和目标 JMS 资源是用 JNDI 进行查找的,源消息供应商或消息中介的 JNDI 查找类必须捆绑在 JBoss 模块里。下面的过程使用了虚拟的 'MyCustomMQ' 消息中介作为例子。- 为消息供应商创建 JBoss 模块。
- 在
EAP_HOME/modules/system/layers/base/下为新的模块创建一个目录结构。main/子目录将包含客户 JAR 和module.xml文件。下面是为消息供应商 MyCustomMQ 创建的一个目录结构示例:EAP_HOME/modules/system/layers/base/org/mycustommq/main/。 - 在
main/子目录里,创建一个包含消息供应商的模块定义的module.xml文件。下面是为消息供应商 MyCustomMQ 创建的module.xml示例。<?xml version="1.0" encoding="UTF-8"?> <module xmlns="urn:jboss:module:1.1" name="org.mycustommq"> <properties> <property name="jboss.api" value="private"/> </properties> <resources> <!-- Insert resources required to connect to the source or target --> <resource-root path="mycustommq-1.2.3.jar" /> <resource-root path="mylogapi-0.0.1.jar" /> </resources> <dependencies> <!-- Add the dependencies required by JMS Bridge code --> <module name="javax.api" /> <module name="javax.jms.api" /> <module name="javax.transaction.api"/> <!-- Add a dependency on the org.hornetq module since we send --> <!-- messages tothe HornetQ server embedded in the local EAP instance --> <module name="org.hornetq" /> </dependencies> </module> - 从源资源复制消息供应商用于 JNDI 查找的的 JAR 到模块的
main/子目录。MyCustomMQ 模块的目录结构应该类似于:modules/ `-- system `-- layers `-- base `-- org `-- mycustommq `-- main |-- mycustommq-1.2.3.jar |-- mylogapi-0.0.1.jar |-- module.xml
- 配置部署到 JBoss EAP 6 服务器的
messaging子系统的 JMS 桥。- 在开始之前,请先停止服务器并备份当前的服务器配置文件。如果是作为独立服务器运行,它是
EAP_HOME/standalone/configuration/standalone-full-ha.xml。如果是运行的受管域,请备份EAP_HOME/domain/configuration/domain.xml以及EAP_HOME/domain/configuration/host.xml。 - 在服务器配置文件里的
messaging子系统里添加jms-bridge元素。source和target元素提供的用于 JNDI 查找的 JMS 资源的名称。如果指定了user和password凭证,当创建 JMS 连接时它们会作为参数传入。下面是一个为消息供应商 MyCustomMQ 配置的jms-bridge元素例子:<subsystem xmlns="urn:jboss:domain:messaging:1.3"> ... <jms-bridge name="myBridge" module="org.mycustommq"> <source> <connection-factory name="ConnectionFactory"/> <destination name="sourceQ"/> <user>user1</user> <password>pwd1</password> <context> <property key="java.naming.factory.initial" value="org.mycustommq.jndi.MyCustomMQInitialContextFactory"/> <property key="java.naming.provider.url" value="tcp://127.0.0.1:9292"/> </context> </source> <target> <connection-factory name="java:/ConnectionFactory"/> <destination name="/jms/targetQ"/> </target> <quality-of-service>DUPLICATES_OK</quality-of-service> <failure-retry-interval>500</failure-retry-interval> <max-retries>1</max-retries> <max-batch-size>500</max-batch-size> <max-batch-time>500</max-batch-time> <add-messageID-in-header>true</add-messageID-in-header> </jms-bridge> </subsystem>在上面的例子里,JNDI 属性是在source的context元素里定义的。如上面的target例子,如果忽略了context元素,JMS 资源将在本地实例里进行查找。

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.