rabbitmq使用

 RabbitMQ

 

消息队列的使用过程大概如下:

1)客户端连接到消息队列服务器,打开一个channel
2)客户端声明一个exchange,并设置相关属性。
3)客户端声明一个queue,并设置相关属性。
4)客户端使用routing key,在exchangequeue之间建立好绑定关系。
5)客户端投递消息到exchange

 

 

 

1、了解Rabbitmq的使用及web监控工具的使用

2、停止rabbitMQ应用,关闭节点 : rabbitmqctl stop

3、停止rabbitMQ应用 : rabbitmqctl stop_app

4、 启动rabbitMQ应用 : rabbitmqctl start_app

5、关闭rabbit服务 ./rabbitmqctl stop

6、启动rabbit服务 rabbitmq-server start

7、重启rabbit服务 rabbitmq-server restart

8、连接情况

9、启动插件:rabbitmq-plugins enable rabbitmq_management

 

 

10、消息通道情况

 

 

 

11、Exchange绑定情况

 

 

12、Queue创建绑定情况

 

 

 

13、启动trace插件(查看日志使用)

(1)(查看已安装的插件)进入安装目录,查看是否已经安装,执行命令./rabbitmq-plugins list

 

 

 

 

(2)、未安装先安装下插件

启动./rabbitmq-plugins enable rabbitmq_tracing

 

 

 

 

(3)、添加一个跟踪日志

 

 

16、spring配置

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc"

    xmlns:context="http://www.springframework.org/schema/context" xmlns:cache="http://www.springframework.org/schema/cache"

    xmlns:rabbit="http://www.springframework.org/schema/rabbit"

    xsi:schemaLocation="

      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd

      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd

      http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd

      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd

      http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd

      http://www.springframework.org/schema/rabbit

      http://www.springframework.org/schema/rabbit/spring-rabbit-1.0.xsd"

     default-autowire="byName" default-lazy-init="false">

    

      <!--连接服务配置  -->

 

     <rabbit:connection-factory id="connectionFactory" host="*.*.*.*" username="admin"  password="*" port="5672" />

 

     <rabbit:admin connection-factory="connectionFactory"/>

     

     <!-- queue 队列声明-->

 

     <rabbit:queue id="queue_one" durable="true" auto-delete="false" exclusive="false" name="queue_one"/>

     <rabbit:queue id="queue_two" durable="true" auto-delete="false" exclusive="false" name="queue_two"/>

 

 

   <!--exchange queue binging key 绑定 -->

 

    <rabbit:direct-exchange name="my-mq-exchange" durable="true" auto-delete="false" id="my-mq-exchange">

    <rabbit:bindings>

     <rabbit:binding queue="queue_one" key="queue_one_key"/>

     <rabbit:binding queue="queue_two" key="queue_two_key"/>

    </rabbit:bindings>

    </rabbit:direct-exchange>

 

     

 

    <!--spring amqp默认的是jackson 的一个插件,目的将生产者生产的数据转换为json存入消息队列,由于fastjson的速度快于jackson,这里替换为fastjson的一个实现 -->

 

    <bean id="jsonMessageConverter"  class="com.ailk.jike.modules.rabitmq3.FastJsonMessageConverter"></bean>

    

     

 

    <!--spring template声明-->

 

    <rabbit:template exchange="my-mq-exchange" id="amqpTemplate"  connection-factory="connectionFactory"  message-converter="jsonMessageConverter"/>

    

    <!--queue litener  观察 监听模式 当有消息到达时会通知监听在对应的队列上的监听对象-->

 

    <rabbit:listener-container connection-factory="connectionFactory" acknowledge="auto" >

        <rabbit:listener queues="queue_one" ref="queueOneLitener"/>

        <rabbit:listener queues="queue_two" ref="publishCustomerListener"/>

    </rabbit:listener-container>

</beans>

 

posted @ 2017-06-05 10:16  六月飞鸟  阅读(666)  评论(0)    收藏  举报