Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Rabbitmq 使用重试模板使用Spring AMQP配置重试功能时出现问题_Rabbitmq_Spring Amqp_Spring Retry - Fatal编程技术网

Rabbitmq 使用重试模板使用Spring AMQP配置重试功能时出现问题

Rabbitmq 使用重试模板使用Spring AMQP配置重试功能时出现问题,rabbitmq,spring-amqp,spring-retry,Rabbitmq,Spring Amqp,Spring Retry,我正在尝试在我的Spring集成项目中配置重试功能,在该项目中,我尝试按照第3.3.1节中提供的详细信息连接到Rabbit服务器。但看起来重试策略没有生效。 这是我配置中的配置: <!-- Spring AMQP Template --> <rabbit:template id="amqpTemplate" connection-factory="connectionFactory" retry-template="retryTemplate" exchange=

我正在尝试在我的Spring集成项目中配置重试功能,在该项目中,我尝试按照第3.3.1节中提供的详细信息连接到Rabbit服务器。但看起来重试策略没有生效。 这是我配置中的配置:

<!-- Spring AMQP Template -->
<rabbit:template id="amqpTemplate" connection-factory="connectionFactory"   retry-template="retryTemplate"
    exchange="myExchange" />

<bean id="retryTemplate" class="org.springframework.retry.support.RetryTemplate">
    <property name="backOffPolicy">
        <bean class="org.springframework.retry.backoff.ExponentialBackOffPolicy">
            <property name="initialInterval" value="8" />
            <property name="multiplier" value="100.0" />
            <property name="maxInterval" value="100000" />
        </bean>
    </property>
    <property name="retryPolicy">
        <bean class="org.springframework.retry.policy.SimpleRetryPolicy">
            <property name="maxAttempts" value="3"/>
        </bean>
    </property>         
</bean>
<!-- Spring AMQP Admin -->
<rabbit:admin connection-factory="connectionFactory" />

根据代码片段,我预计重试将以指数间隔发生3次。但根据日志,我看到重试尝试以7秒的间隔进行,并且一直持续(3次后不会停止)

<!-- Spring AMQP Template -->
<rabbit:template id="amqpTemplate" connection-factory="connectionFactory"   retry-template="retryTemplate"
    exchange="myExchange" />

<bean id="retryTemplate" class="org.springframework.retry.support.RetryTemplate">
    <property name="backOffPolicy">
        <bean class="org.springframework.retry.backoff.ExponentialBackOffPolicy">
            <property name="initialInterval" value="8" />
            <property name="multiplier" value="100.0" />
            <property name="maxInterval" value="100000" />
        </bean>
    </property>
    <property name="retryPolicy">
        <bean class="org.springframework.retry.policy.SimpleRetryPolicy">
            <property name="maxAttempts" value="3"/>
        </bean>
    </property>         
</bean>
<!-- Spring AMQP Admin -->
<rabbit:admin connection-factory="connectionFactory" />

想知道是否有人能指出我的配置中的错误。

首先,
maxtures=3
意味着3次尝试(2次重试),因此您应该看到最初的尝试,8毫秒后的第二次尝试,800毫秒后的最后一次尝试

<!-- Spring AMQP Template -->
<rabbit:template id="amqpTemplate" connection-factory="connectionFactory"   retry-template="retryTemplate"
    exchange="myExchange" />

<bean id="retryTemplate" class="org.springframework.retry.support.RetryTemplate">
    <property name="backOffPolicy">
        <bean class="org.springframework.retry.backoff.ExponentialBackOffPolicy">
            <property name="initialInterval" value="8" />
            <property name="multiplier" value="100.0" />
            <property name="maxInterval" value="100000" />
        </bean>
    </property>
    <property name="retryPolicy">
        <bean class="org.springframework.retry.policy.SimpleRetryPolicy">
            <property name="maxAttempts" value="3"/>
        </bean>
    </property>         
</bean>
<!-- Spring AMQP Admin -->
<rabbit:admin connection-factory="connectionFactory" />
倍增100似乎过多-下一次尝试(如果maxattempts为4)将在80秒后进行

<!-- Spring AMQP Template -->
<rabbit:template id="amqpTemplate" connection-factory="connectionFactory"   retry-template="retryTemplate"
    exchange="myExchange" />

<bean id="retryTemplate" class="org.springframework.retry.support.RetryTemplate">
    <property name="backOffPolicy">
        <bean class="org.springframework.retry.backoff.ExponentialBackOffPolicy">
            <property name="initialInterval" value="8" />
            <property name="multiplier" value="100.0" />
            <property name="maxInterval" value="100000" />
        </bean>
    </property>
    <property name="retryPolicy">
        <bean class="org.springframework.retry.policy.SimpleRetryPolicy">
            <property name="maxAttempts" value="3"/>
        </bean>
    </property>         
</bean>
<!-- Spring AMQP Admin -->
<rabbit:admin connection-factory="connectionFactory" />

我建议您打开调试日志以跟踪重试进度。

谢谢您的回复。当我打开日志记录时,我看到使用的是SimpleMessageListenerContainer的默认_RECOVERY_间隔。从日志中:09:01:52077调试[org.springframework.amqp.rabbit.listener.BlockingQueueConsumer](SimpleAsynctaskeExecutor-4)启动使用者:tags=[{}],channel=null,acknowledgeMode=自动本地队列大小=0 09:01:53079调试[org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer](SimpleAsynctaskeExecutor-4)在5000毫秒内恢复消费者。因此,这是5秒,而不是7秒,但想知道为什么RetryPolicy不启动inNo;您在
rabbitmplate
中进行了重试-重试与消息侦听器容器无关-当然,如果存在连接问题,则两者都会受到影响。消息到达容器中;假设您正在容器线程上调用模板。将尝试重试;耗尽时,异常将被抛出回容器。如果需要帮助,您需要提供更多有关应用程序的信息。如果你无法从日志中找到答案,请将它们与完整配置一起发布到某个地方(如果它们太大,则发布一个要点)。想知道我是否试图错误地使用RetryTemplate。我的应用程序从rabbitMQ(服务器A)中拾取消息,转换数据,然后放到不同的rabbitMQ(服务器B)上。我意识到的是,如果我关闭了ServerB,重试就会起作用……我可以看到基于retryPolicy进行的atempts,并在尝试用尽后抛出异常。现在,当我关闭服务器A时,我可以看到侦听器容器以5秒的间隔重复尝试连接到服务器A。是否有方法在侦听器容器级别应用retrypolicy?使用-向侦听器容器添加建议链,要求发送方提供
messageId
头来管理重试的状态。无状态通知将在容器内重试,而不会返回容器(直到重试次数用尽且没有恢复程序为止)。感谢链接。摘自文章:如果故障是由断开的连接(不是业务异常)引起的,那么必须取消并重新启动为侦听器收集消息的使用者。SimpleMessageListenerContainer无休止地循环试图重新启动使用者。。。。。一个副作用是,如果代理在容器启动时关闭,它将继续尝试,直到可以建立连接。想知道是否有方法应用retrypolicy以便控制容器的重新启动…hi ignatan。。我也面临同样的问题,你能给我一个解决方案吗#谢谢
<!-- Spring AMQP Template -->
<rabbit:template id="amqpTemplate" connection-factory="connectionFactory"   retry-template="retryTemplate"
    exchange="myExchange" />

<bean id="retryTemplate" class="org.springframework.retry.support.RetryTemplate">
    <property name="backOffPolicy">
        <bean class="org.springframework.retry.backoff.ExponentialBackOffPolicy">
            <property name="initialInterval" value="8" />
            <property name="multiplier" value="100.0" />
            <property name="maxInterval" value="100000" />
        </bean>
    </property>
    <property name="retryPolicy">
        <bean class="org.springframework.retry.policy.SimpleRetryPolicy">
            <property name="maxAttempts" value="3"/>
        </bean>
    </property>         
</bean>
<!-- Spring AMQP Admin -->
<rabbit:admin connection-factory="connectionFactory" />