6

ActiveMQ与RabbitMQ使用camel集成

 3 years ago
source link: https://blog.csdn.net/KimmKing/article/details/24427383
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

         著名的EIP实现框架Camel最早起源于ActiveMQ内的一些基于消息的集成需求,然后逐渐发展成为一个ActiveMQ的子项目,最后这一块的功能越来越完善,就成为了Apache的顶级项目。

         所以,从一开始到现在,ActiveMQ与Camel这两个项目一直都是紧密联系的,可以非常方便的整合使用:比如在ActiveMQ的配置文件中直接按照Spring的配置方式使用Camel来实现ActiveMQ与其他外部系统或中间件的集成。而ActiveMQ中的一些简单的集成功能也越来越倾向于直接去掉或者移植到Camel环境中去实现。

环境:ActiveMQ 5.9.0、RabbitMQ3.3.0、

一、ActiveMQ与ActiveMQ的集成

实现一个简单的从一个Queue到另一个Queue的消息转发。

1.        在activemq.xml中加一句:<import resource="camel.xml"/>

2.        加一个简单路由,从队列example.A转发消息到队列example.B,camel.xml的内容为:

 3.        启动ActiveMQ后,浏览器输入http://localhost:8161/admin/queues.jsp,可以看到自动创建了一个队列example.A,并且加了一个消费者。

4.        点击Send To,发送一个消息到example.A,刷新页面,可以看到消息已经被转发:

二、ActiveMQ与RabbitMQ集成

详细的配置参数:http://camel.apache.org/rabbitmq.html

Ø  从RabbitMQ路由消息到ActiveMQ

1.        Camel里添加AMQP的路由如下:

2.        复制camel中的camel-rabbitmq-2.13.0.jar 和rabbitmq-java-client中的rabbitmq-client.jar到apache-activemq-5.9.0\lib\camel下。

3.        重启ActiveMQ,在rabbitmq的控制台可以看到自动创建的exchange为t,

4.        在rabbitmq控制台向t中发送消息,

5.        刷新ActiveMQ控制台可以看到消息已经从rabbitmq路由到activemq:

Ø  从ActiveMQ路由消息到Rabbitmq

1.        在camel.xml中添加配置:

2.        重启ActiveMQ后,在控制台可以看到新增的队列test,

3.        往ActiveMQ的test队列发送一个消息。

4.        写个简单程序从Rabbitmq的队列test接收消息:

说明消息已经转发从ActiveMQ到RabbitMQ了。

各软件下载地址:


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK