RabbitMq配置
来源:互联网 发布:javascript 方法写法 编辑:程序博客网 时间:2024/05/18 09:36
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit-1.0.xsd">
<context:annotation-config />
<!-- 连接服务配置 -->
<rabbit:connection-factory id="connectionFactory"
host="${mq.db.url}" username="guest" password="guest" />
<rabbit:template id="discuss.action.Template" connection-factory="connectionFactory" exchange="discuss.action.exchange" encoding="UTF-8" />
<rabbit:template id="discuss.news.Template" connection-factory="connectionFactory" exchange="discuss.news.exchange" encoding="UTF-8" />
<rabbit:template id="discuss.mine.Template" connection-factory="connectionFactory" exchange="discuss.mine.exchange" encoding="UTF-8" />
<rabbit:template id="discuss.topic.Template" connection-factory="connectionFactory" exchange="discuss.topic.exchange" encoding="UTF-8" />
<rabbit:queue name="discuss.action.queue" auto-delete="false" exclusive="false" durable="true" />
<rabbit:queue name="discuss.log.queue" auto-delete="false" exclusive="false" durable="true" />
<rabbit:queue name="discuss.follow.queue" auto-delete="false" exclusive="false" durable="true" />
<rabbit:queue name="discuss.news.queue" auto-delete="false" exclusive="false" durable="true" />
<rabbit:queue name="discuss.mine.queue" auto-delete="false" exclusive="false" durable="true" />
<rabbit:queue name="discuss.mail.queue" auto-delete="false" exclusive="false" durable="true" />
《配置交换机所绑定的队列》
<!-- 子网广播模式(发布/订阅模式),最快,不需路由,转发所有队列 -->
<rabbit:fanout-exchange name="discuss.action.exchange" durable="true">
<rabbit:bindings>
<rabbit:binding queue="discuss.action.queue" />
</rabbit:bindings>
</rabbit:fanout-exchange>
<rabbit:fanout-exchange name="discuss.news.exchange" durable="true">
<rabbit:bindings>
<rabbit:binding queue="discuss.news.queue" />
</rabbit:bindings>
</rabbit:fanout-exchange>
<rabbit:fanout-exchange name="discuss.mine.exchange" durable="true">
<rabbit:bindings>
<rabbit:binding queue="discuss.mine.queue" />
</rabbit:bindings>
</rabbit:fanout-exchange>
《路由模式,配置其对应的队列,pattern就是路由的配置》
<!-- 路由模式(按topic发送接收),需要指定路由键 -->
<rabbit:topic-exchange name="discuss.topic.exchange" durable="true">
<rabbit:bindings>
<rabbit:binding queue="discuss.log.queue" pattern="discuss.log.#" />
<rabbit:binding queue="discuss.mail.queue" pattern="discuss.mail.#" />
</rabbit:bindings>
</rabbit:topic-exchange>
《配置消费者,由相应的类侦听相应的队列,列的一个方法侦听一个队列的消息,执行时间之前服务器重启,消息继续执行,执行时间之后重启,消息跳过》
<rabbit:listener-container connection-factory="connectionFactory" message-converter="jacksonConverter" acknowledge="auto">
<rabbit:listener ref="consumeHandler" method="action" queue-names="discuss.action.queue" />
<rabbit:listener ref="consumeHandler" method="log" queue-names="discuss.log.queue" />
<rabbit:listener ref="consumeHandler" method="news" queue-names="discuss.news.queue" />
<rabbit:listener ref="consumeHandler" method="mine" queue-names="discuss.mine.queue" />
<rabbit:listener ref="consumeHandler" method="mail" queue-names="discuss.mail.queue" />
</rabbit:listener-container>
《配置消费类和字符串转换工具类》
<bean id="consumeHandler" class="net.tfedu.discuss.mq.service.impl.ConsumeManagerImpl" />
<bean id="jacksonConverter" class="net.tfedu.discuss.mq.service.FastJsonMessageConverter" />
</beans>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit-1.0.xsd">
<context:annotation-config />
<!-- 连接服务配置 -->
<rabbit:connection-factory id="connectionFactory"
host="${mq.db.url}" username="guest" password="guest" />
<rabbit:admin connection-factory="connectionFactory" />
《生产者配置,生成相应的消息,定义其对应的交换机》
<rabbit:template id="discuss.action.Template" connection-factory="connectionFactory" exchange="discuss.action.exchange" encoding="UTF-8" />
<rabbit:template id="discuss.news.Template" connection-factory="connectionFactory" exchange="discuss.news.exchange" encoding="UTF-8" />
<rabbit:template id="discuss.mine.Template" connection-factory="connectionFactory" exchange="discuss.mine.exchange" encoding="UTF-8" />
<rabbit:template id="discuss.topic.Template" connection-factory="connectionFactory" exchange="discuss.topic.exchange" encoding="UTF-8" />
《接收消息的队列》
<rabbit:queue name="discuss.action.queue" auto-delete="false" exclusive="false" durable="true" />
<rabbit:queue name="discuss.log.queue" auto-delete="false" exclusive="false" durable="true" />
<rabbit:queue name="discuss.follow.queue" auto-delete="false" exclusive="false" durable="true" />
<rabbit:queue name="discuss.news.queue" auto-delete="false" exclusive="false" durable="true" />
<rabbit:queue name="discuss.mine.queue" auto-delete="false" exclusive="false" durable="true" />
<rabbit:queue name="discuss.mail.queue" auto-delete="false" exclusive="false" durable="true" />
《配置交换机所绑定的队列》
<!-- 子网广播模式(发布/订阅模式),最快,不需路由,转发所有队列 -->
<rabbit:fanout-exchange name="discuss.action.exchange" durable="true">
<rabbit:bindings>
<rabbit:binding queue="discuss.action.queue" />
</rabbit:bindings>
</rabbit:fanout-exchange>
<rabbit:fanout-exchange name="discuss.news.exchange" durable="true">
<rabbit:bindings>
<rabbit:binding queue="discuss.news.queue" />
</rabbit:bindings>
</rabbit:fanout-exchange>
<rabbit:fanout-exchange name="discuss.mine.exchange" durable="true">
<rabbit:bindings>
<rabbit:binding queue="discuss.mine.queue" />
</rabbit:bindings>
</rabbit:fanout-exchange>
《路由模式,配置其对应的队列,pattern就是路由的配置》
<!-- 路由模式(按topic发送接收),需要指定路由键 -->
<rabbit:topic-exchange name="discuss.topic.exchange" durable="true">
<rabbit:bindings>
<rabbit:binding queue="discuss.log.queue" pattern="discuss.log.#" />
<rabbit:binding queue="discuss.mail.queue" pattern="discuss.mail.#" />
</rabbit:bindings>
</rabbit:topic-exchange>
《配置消费者,由相应的类侦听相应的队列,列的一个方法侦听一个队列的消息,执行时间之前服务器重启,消息继续执行,执行时间之后重启,消息跳过》
<rabbit:listener-container connection-factory="connectionFactory" message-converter="jacksonConverter" acknowledge="auto">
<rabbit:listener ref="consumeHandler" method="action" queue-names="discuss.action.queue" />
<rabbit:listener ref="consumeHandler" method="log" queue-names="discuss.log.queue" />
<rabbit:listener ref="consumeHandler" method="news" queue-names="discuss.news.queue" />
<rabbit:listener ref="consumeHandler" method="mine" queue-names="discuss.mine.queue" />
<rabbit:listener ref="consumeHandler" method="mail" queue-names="discuss.mail.queue" />
</rabbit:listener-container>
《配置消费类和字符串转换工具类》
<bean id="consumeHandler" class="net.tfedu.discuss.mq.service.impl.ConsumeManagerImpl" />
<bean id="jacksonConverter" class="net.tfedu.discuss.mq.service.FastJsonMessageConverter" />
</beans>
0 0
- RabbitMq配置
- rabbitmq 配置
- rabbitmq配置
- rabbitmq配置
- RabbitMQ安装配置手册
- rabbitmq 安装配置
- rabbitmq安装配置手记
- RabbitMQ集群配置
- RabbitMQ虚拟主机配置
- RabbitMq的配置
- Rabbitmq的安装配置
- Spring + RabbitMQ 配置
- rabbitMQ安装配置
- rabbitmq安装和配置
- spring的rabbitmq配置
- RabbitMQ安装配置学习
- RabbitMQ shovel配置
- rabbitmq 配置详解
- 多维度的架构分解
- 股份的计划规划高发的发斯蒂芬呃呃呃
- android 手势操作GestureDetector
- Struts2注解配置
- NDK-Java调用C++文件
- RabbitMq配置
- java自带线程池和队列详细讲解
- java中Thread与Runnable的区别
- 用php实现引用cacti中的流量图表
- 磨刀不误砍材工 - 环境搭建(为什么要配置环境变量)
- Hadoop HDFS数据完整性
- jQuery入门学习六:可收缩展开的级联菜单
- Floyd算法——C语言实现
- Robotium第一篇之心里闹腾