lishijian 2019-10-30
1. 创建队列WorkQueue,并把WorkQueue跟exchangeWork绑定;
2. 创建队列DLXQueue,并把DLXQueue跟exchangeDLX绑定;
a. 设置DLXQueue队列参数:
x-dead-letter-exchange 为DLXQueue
x-message-ttl 5000 单位毫秒
3. 将设置WorkQueue和DLXQueue两个exchange路由key都为DLXQueue(默认)
4. 设置exchangeDLX绑定exchangeWork,路由key为DLXQueue。
研华
spring 配置示例:
<?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:rabbit="http://www.springframework.org/schema/rabbit"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit-1.1.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
工控机
<!-- 定义rabbitmq连接工厂,生产环境使用集群配置,支持failover -->
<rabbit:connection-factory id="connectionFactory" publisher-confirms="true" addresses="${rabbitmq.host}" />
<rabbit:admin connection-factory="connectionFactory"/>
<bean id="jsonMessageConverter" class="org.springframework.amqp.support.converter.JsonMessageConverter">
<property name="classMapper">
<bean class="org.springframework.amqp.support.converter.DefaultClassMapper"/>
</property>
</bean>
<rabbit:template id="amqpTemplate" connection-factory="connectionFactory" message-converter="jsonMessageConverter"/>