admin
2025-02-20 f537abe9f3646c739beaf15076246a2f71a347e9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?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>