ActiveMQ(五):多个系统间消息的使用

来源:互联网 发布:strider军刀 淘宝 编辑:程序博客网 时间:2024/03/29 15:33

连接在同一个ActiveMQ,一个系统可以监听其他系统的消息发出的消息




例子:

1.两个系统一个系统发送消息,一个系统负责监听



2.配置文件:消息的发送方和监听方都连接到同一个 ActiveMQ地址上

发送方

    <amq:connectionFactory id="amqConnectionFactory"         brokerURL="tcp://localhost:61616"         userName="admin"         password="admin" />        <!-- 配置JMS连接工长 -->    <bean id="connectionFactory"        class="org.springframework.jms.connection.CachingConnectionFactory">        <constructor-arg ref="amqConnectionFactory" />        <property name="sessionCacheSize" value="100" />    </bean>        <!-- 定义消息队列(Queue) -->    <bean id="queueDestination" class="org.apache.activemq.command.ActiveMQQueue">        <!-- 设置消息队列的名字 -->        <constructor-arg>            <value>queue.activemq</value>        </constructor-arg>    </bean>        <!-- 定义消息队列(Topic) -->    <bean id="topicDestination" class="org.apache.activemq.command.ActiveMQTopic">        <!-- 设置消息队列的名字 -->        <constructor-arg>            <value>topic3.activemq</value>        </constructor-arg>    </bean>


接收方


 <amq:connectionFactory id="amqConnectionFactory"         brokerURL="tcp://localhost:61616"         userName="admin"         password="admin" /> <!-- 定义消息队列(Topic) -->    <bean id="topicDestination" class="org.apache.activemq.command.ActiveMQTopic">        <!-- 设置消息队列的名字 -->        <constructor-arg>            <value>topic3.activemq</value>        </constructor-arg>    </bean> <!-- 定义Topic监听器 --> <!-- 多一个消费者监听 同一个Topic的消息 --><jms:listener-container destination-type="topic" container-type="default" connection-factory="connectionFactory" acknowledge="auto"><jms:listener destination="topic1.activemq" ref="topicMessageListener1"/><jms:listener destination="topic1.activemq" ref="topicMessageListener2"/><jms:listener destination="topic3.activemq" ref="topicMessageListener3"/></jms:listener-container>


3.

发送


接收



原创粉丝点击