zoukankan      html  css  js  c++  java
  • 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.0libcamel下。

    3.        重新启动ActiveMQ,在rabbitmq的控制台能够看到自己主动创建的exchange为t。

     

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


    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接收消息:

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

    各软件下载地址:

    1. 下载安装erlang:http://www.erlang.org/download.html
    2. 下载解压rabbitmq zip版本号及java bin client zip:http://www.rabbitmq.com/download.html
    3. 加入控制台:http://www.rabbitmq.com/management.html
    4. Camel下载:http://camel.apache.org/download.html
    5. ActiveMQ下载:http://activemq.apache.org/download.html

     

     

    版权声明:本文博主原创文章。博客,未经同意不得转载。

  • 相关阅读:
    CSS div固定顶端
    制定计划
    jquery判断浏览器类型
    JSTL
    Exception loading sessions from persistent storage
    转载了个js代码
    做了个球状进度条
    IE6下input标签border问题
    多端口站点设置,以APMSERV集成环境为例!
    2017最全的php面试题目及答案总结
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/4810563.html
Copyright © 2011-2022 走看看