ActiveMQ与RabbitMQ采用camel综合
著名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的内容为:
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://camel.apache.org/schema/springhttp://camel.apache.org/schema/spring/camel-spring.xsd
http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd"> <camelContext id="camel"xmlns="http://camel.apache.org/schema/spring">
<route>
<description>Example Camel Route</description>
<from uri="activemq:example.A"/>
<to uri="activemq:example.B"/>
</route>
</camelContext> <bean id="activemq"class="org.apache.activemq.camel.component.ActiveMQComponent" >
<property name="connectionFactory">
<beanclass="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL"value="vm://localhost?create=true"/>
<property name="userName"value="${activemq.username}"/>
<property name="password" value="${activemq.password}"/>
</bean>
</property>
</bean>
</beans>
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的路由例如以下:
<route>
<from uri="rabbitmq://localhost/t?username=guest&password=guest&exchangeType=topic&autoDelete=false&queue=t"/>
<to uri="activemq:example.fromRMQ"/>
</route>
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中发送消息,
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvS2ltbUtpbmc=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
5. 刷新ActiveMQ控制台能够看到消息已经从rabbitmq路由到activemq:
Ø 从ActiveMQ路由消息到Rabbitmq
1. 在camel.xml中加入配置:
<route>
<from uri="activemq:test"/>
<to uri="rabbitmq://localhost/?username=guest&password=guest&exchangeType=topic&autoDelete=false&queue=test"/>
</route>
2. 重新启动ActiveMQ后,在控制台能够看到新增的队列test,
3. 往ActiveMQ的test队列发送一个消息。
4. 写个简单程序从Rabbitmq的队列test接收消息:
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvS2ltbUtpbmc=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
说明消息已经转发从ActiveMQ到RabbitMQ了。
各软件下载地址:
- 下载安装erlang:http://www.erlang.org/download.html
- 下载解压rabbitmq zip版本号及java bin client zip:http://www.rabbitmq.com/download.html
- 加入控制台:http://www.rabbitmq.com/management.html
- Camel下载:http://camel.apache.org/download.html
- ActiveMQ下载:http://activemq.apache.org/download.html
版权声明:本文博主原创文章。博客,未经同意不得转载。
ActiveMQ与RabbitMQ采用camel综合的更多相关文章
- 20190418 CentOS7实用技能综合:系统安装 + WinScp客户端连接 + 防火墙端口号iptables + Nginx编译安装 + MySQL编译安装 + Redis编译安装 + MongoDB编译安装 + ActiveMQ/RocketMQ/RabbitMQ编译安装 + ...各类常用生产环境软件的编译安装
系统安装 + WinScp客户端连接 + 防火墙端口号iptables + Nginx编译安装 + MySQL编译安装 + Redis编译安装 + MongoDB编译安装 + ActiveMQ/Roc ...
- 消息中间件ActiveMQ、RabbitMQ、RocketMQ、ZeroMQ、Kafka如何选型?
最近要为公司的消息队列中间件进行选型,市面上相关的开源技术又非常多,如ActiveMQ.RabbitMQ.ZeroMQ.Kafka,还有阿里巴巴的RocketMQ等. 这么多技术,如何进行选型呢? 首 ...
- 关于消息队列的使用----ActiveMQ,RabbitMQ,ZeroMQ,Kafka,MetaMQ,RocketMQ
一.消息队列概述消息队列中间件是分布式系统中重要的组件,主要解决应用解耦,异步消息,流量削锋等问题,实现高性能,高可用,可伸缩和最终一致性架构.目前使用较多的消息队列有ActiveMQ,RabbitM ...
- ActiveMQ、RabbitMQ、RocketMQ、Kafka四种消息中间件分析介绍
ActiveMQ.RabbitMQ.RocketMQ.Kafka四种消息中间件分析介绍 我们从四种消息中间件的介绍到基本使用,以及高可用,消息重复性,消息丢失,消息顺序性能方面进行分析介绍! 一.消息 ...
- 消息队列性能对比——ActiveMQ、RabbitMQ与ZeroMQ(译文)
Dissecting Message Queues 概述: 我花了一些时间解剖各种库执行分布式消息.在这个分析中,我看了几个不同的方面,包括API特性,易于部署和维护,以及性能质量..消息队列已经被分 ...
- ActiveMQ;RabbitMQ;ZeroMQ
中间件类型: Embedded middleware: As the name suggests, this typeof middleware handles embedded applicatio ...
- Kafka、ActiveMQ、RabbitMQ、RocketMQ 区别以及高可用原理
为什么使用消息队列 其实就是问问你消息队列都有哪些使用场景,然后你项目里具体是什么场景,说说你在这个场景里用消息队列是什么? 面试官问你这个问题,期望的一个回答是说,你们公司有个什么业务场景,这个业务 ...
- ActiveMQ、RabbitMQ、RocketMQ、Kafka 对比(图示)
RabbitMQ 和 Kafka 对比,一篇好的介绍文章:https://my.oschina.net/u/236698/blog/501834 ActiveMQ.RabbitMQ.RocketMQ. ...
- activemq、rabbitmq、kafka原理和比较
一.activemq 虽然是java写的消息队列,但是提供Java, C, C++, C#, Ruby, Perl, Python, PHP各种客户端,所以语言上是没什么问题的.配置和使用,基本上是j ...
随机推荐
- WCF配置文件
因为要上传较大的图片,WCF传递数组的默认的最大数组16KB就不够了.以下讲解配置内容. 服务端配置 这里一个WCF项目中有1个服务,配置文件如下(位于system.serviceModel标签中): ...
- Oracle SQL Lesson (9) - 操作数据(增删改)
使用INSERT语句INSERT INTO table [(column [, column...])]VALUES (value [, value...]); INSERT INTO departm ...
- AES加密 C++调用Crypto++加密库 样例
这阵子写了一些数据加密的小程序,对照了好几种算法后,选择了AES,高级加密标准(英语:Advanced Encryption Standard,缩写:AES).听这名字就非常厉害的样子 预计会搜索到这 ...
- 重新想象 Windows 8 Store Apps (11) - 控件之 ListView 和 GridView
原文:重新想象 Windows 8 Store Apps (11) - 控件之 ListView 和 GridView [源码下载] 重新想象 Windows 8 Store Apps (11) - ...
- 【DP|多重背包可行性】POJ-1014 Dividing
Dividing Time Limit: 1000MS Memory Limit: 10000K Description Marsha and Bill own a collection of mar ...
- CF 148D. Bag of mice (可能性DP)
D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- NAT( 网络地址转换) 实现
NAT基本介绍: 网络地址转换(NAT,Network Address Translation)属接入广域网(WAN)技术.是一种将私有(保留)地址转化为合法IP地址的转换技术,它被广泛应用于各种类型 ...
- Vbox创建COM对象失败
近期在使用vbox时出现下面错误:创建COM对象失败,应用程序将被中断 在CMD里面输入下面命令: C:\Users\Administrator>d: D:\>cd D:\Program ...
- C#如何获得 WINDOWS
版本号
using System; using System.Runtime.InteropServices; namespace GetWindowsVersion { [ StructLayout( La ...
- Chrome console(转)
阅读目录 写在前面 谷歌控制台Elements面板 查看元素上绑定的事情 样式操作 总况 console.log console.info console.error console.warn con ...