<?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"
|
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.xsd">
|
|
<rabbit:connection-factory id="connectionFactory"
|
host="${rabbitmq.host}"
|
port="${rabbitmq.port}"
|
username="${rabbitmq.username}"
|
password="${rabbitmq.password}"
|
virtual-host="${rabbitmq.virtual-host}" />
|
<!--定义管理交换机、队列-->
|
<rabbit:admin connection-factory="connectionFactory"/>
|
|
<!-- rabbitTemplate-->
|
<rabbit:template id="rabbitTemplate" connection-factory="connectionFactory" retry-template="retryTemplate" />
|
|
<!-- Retry Template -->
|
<bean id="retryTemplate" class="org.springframework.retry.support.RetryTemplate">
|
<property name="backOffPolicy">
|
<bean class="org.springframework.retry.backoff.ExponentialBackOffPolicy">
|
<property name="initialInterval" value="1000"/> <!-- 初始间隔 -->
|
<property name="multiplier" value="3"/> <!-- 乘数 -->
|
<property name="maxInterval" value="30000"/> <!-- 最大间隔 -->
|
</bean>
|
</property>
|
<property name="retryPolicy">
|
<bean class="org.springframework.retry.policy.SimpleRetryPolicy">
|
<property name="maxAttempts" value="5"></property>
|
</bean>
|
</property>
|
</bean>
|
|
|
|
|
<rabbit:queue id="deadLetterQueue" name="deadLetterQueue" auto-declare="true">
|
<rabbit:queue-arguments>
|
<entry key="x-message-ttl" value="172800000" value-type="java.lang.Integer"/> <!-- 设置消息 TTL 为 2天 -->
|
</rabbit:queue-arguments>
|
</rabbit:queue>
|
<!-- 定义死信交换机和队列 -->
|
<rabbit:fanout-exchange id="deadLetterExchange" name="dead.letter.exchange" >
|
<rabbit:bindings>
|
<rabbit:binding queue="deadLetterQueue"/>
|
</rabbit:bindings>
|
</rabbit:fanout-exchange>
|
|
|
|
|
</beans>
|