为了在ActiveMQ创建一个通信目的地, 我们通过bin/activemq开始命令启动ActiveMQ,并使用ActiveMQ hawtio控制台(:8161/hawtio),通过浏览ActiveMQ -> Broker -> Localhost -> Queue并选择Create来创建一个新的JMS队列.在这个例子中设置队列名为JMSBridgeTargetQ.
这就是所有必需的配置文件.我们应该可以启动WildFly服务,看到桥接开始工作并连接到ActiveMQ.
13:43:11,959 INFO [org.jboss.as.remoting] (MSC service thread 1-2) JBAS017100: Listening on 127.0.0.1:9999
13:43:12,447 INFO [org.jboss.as.remoting] (MSC service thread 1-2) JBAS017100: Listening on 127.0.0.1:4447
13:43:12,452 INFO [org.jboss.as.connector.deployers.RaXmlDeployer] (MSC service thread 1-2) IJ020001: Required license terms for file:/home/matt/jboss-as-7.2.0.Final/modules/system/layers/base/org/apache/activemq/main/./
13:43:12,511 INFO [org.jboss.as.connector.deployment] (MSC service thread 1-2) JBAS010406: Registered connection factory java:/AMQConnectionFactory
13:43:12,522 INFO [org.jboss.as.connector.deployment] (MSC service thread 1-2) JBAS010405: Registered admin object at java:/queue/JMSBridgeTargetQ
13:43:12,538 INFO [org.hornetq.core.server] (MSC service thread 1-1) HQ221024: Started Netty Acceptor version 3.6.2.Final-c0d783c 127.0.0.1:5455 for CORE protocol
13:43:12,550 INFO [org.jboss.as.connector.deployers.RaXmlDeployer] (MSC service thread 1-2) IJ020002: Deployed: file:/home/matt/jboss-as-7.2.0.Final/modules/system/layers/base/org/apache/activemq/main/./
13:43:12,555 INFO [org.hornetq.core.server] (MSC service thread 1-1) HQ221024: Started Netty Acceptor version 3.6.2.Final-c0d783c 127.0.0.1:5445 for CORE protocol
13:43:12,558 INFO [org.hornetq.core.server] (MSC service thread 1-1) HQ221009: Server is now live
13:43:12,561 INFO [org.hornetq.core.server] (MSC service thread 1-1) HQ221003: HornetQ Server version 2.3.0.CR1 (buzzzzz!, 122) [1ef84f49-88d8-11e3-a2ac-f9239574df9d]
13:43:12,584 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-1) JBAS010400: Bound data source [java:jboss/datasources/ExampleDS]
13:43:12,600 INFO [org.jboss.as.connector.deployment] (MSC service thread 1-1) JBAS010401: Bound JCA ConnectionFactory [java:/AMQConnectionFactory]
13:43:12,611 INFO [org.jboss.as.connector.deployment] (MSC service thread 1-1) JBAS010401: Bound JCA AdminObject [java:/queue/JMSBridgeTargetQ]
13:43:12,683 INFO [org.jboss.as.messaging] (ServerService Thread Pool -- 58) JBAS011601: Bound messaging object to jndi name java:jboss/exported/jms/RemoteConnectionFactory
13:43:12,686 INFO [org.hornetq.core.server] (ServerService Thread Pool -- 60) HQ221005: trying to deploy queue jms.queue.JMSBridgeSourceQueue
13:43:12,733 INFO [org.jboss.as.messaging] (ServerService Thread Pool -- 60) JBAS011601: Bound messaging object to jndi name java:jboss/exported/jms/queue/JMSBridgeSourceQ
13:43:12,738 INFO [org.jboss.as.messaging] (ServerService Thread Pool -- 60) JBAS011601: Bound messaging object to jndi name java:/queue/JMSBridgeSourceQ
13:43:12,747 INFO [org.jboss.as.messaging] (ServerService Thread Pool -- 59) JBAS011601: Bound messaging object to jndi name java:/ConnectionFactory
13:43:12,916 INFO [org.jboss.as.connector.deployment] (MSC service thread 1-2) JBAS010406: Registered connection factory java:/JmsXA
13:43:12,968 INFO [org.hornetq.ra] (MSC service thread 1-2) HornetQ resource adaptor started
13:43:12,969 INFO [org.jboss.as.connector.services.resourceadapters.ResourceAdapterActivatorService$ResourceAdapterActivator] (MSC service thread 1-2) IJ020002: Deployed: file://RaActivatorhornetq-ra
13:43:12,974 INFO [org.jboss.as.connector.deployment] (MSC service thread 1-1) JBAS010401: Bound JCA ConnectionFactory [java:/JmsXA]
13:43:13,286 INFO [org.jboss.messaging] (ServerService Thread Pool -- 58) JBAS011610: Started JMS Bridge simple-jms-bridge
13:43:13,439 INFO [org.jboss.as] (Controller Boot Thread) JBAS015961: Http management interface listening on :9990/management
13:43:13,440 INFO [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on :9990
13:43:13,440 INFO [org.jboss.as] (Controller Boot Thread) JBAS015874: JBoss AS 7.2.0.Final "Janus" started in 9912ms - Started 169 of 228 services (58 services are passive or on-demand)
我们现在可以在JBoss的JMSBridgeSourceQ里面放置消息,它们最后将处于ActiveMQ的JMSBridgeTargetQ之中.
将桥接的消息流方向反过来也是可能的,尽管消费者的桥接和生产者的桥接并非同样至关重要.消费者的桥接,通常更倾向于直接从映射的JNDI名字(在queue/JMSBridgeTargetQ里面,由资源适配器创建)获取消息,而不是将消息放置在本地队列后,再从本地获取消息.