Spring集成RabbitMQ - 重试的监听器

时间:2015-10-17 22:04:38

标签: spring rabbitmq spring-integration spring-amqp

下面是我在rabbitmq listener的xml文件中的声明性配置。使用advic链重试似乎没有发生.DLQMessageRecoverer类正在抛出RabbitmqRejectAndDontRequeue异常。它似乎也没有调用它。

  scope :duebylastresult, -> {
    find_by_sql(
      'SELECT *
       FROM checks
       LEFT OUTER JOIN 
            (SELECT id AS tick_id,
                    check_id AS check_id,
                    date AS tick_date, 
                    result AS tick_result,
                    dense_rank() OVER (
                      PARTITION BY ticks.check_id
                      ORDER BY ticks.date DESC
                    ) AS tick_rank
             FROM ticks) AS ranked_ticks ON checks.id = ranked_ticks.check_id
       WHERE tick_rank = 1 AND tick_result >= 3;'
    )
  }
<bean id="retryAdvice" class="org.springframework.amqp.rabbit.config.StatefulRetryOperationsInterceptorFactoryBean">
    <property name="messageRecoverer" ref="dlqMessageRecoverer"/>
    <!--<property name="messageRecoverer" ref="errorMessageRecoverer"/>-->
    <property name="retryOperations" ref="retryTemplate" />
</bean>

<bean id="dlqMessageRecoverer" class="com.prosper.phlconsumer.service.error.DLQMessageRecoverer" />

<bean id="retryTemplate" class="org.springframework.retry.support.RetryTemplate">
    <property name="backOffPolicy">
        <bean class="org.springframework.retry.backoff.ExponentialBackOffPolicy">
            <property name="initialInterval" value="500000" />
            <property name="maxInterval" value="12000000" />
            <property name="multiplier" value="2" />
        </bean>
    </property>
    <property name="retryPolicy">
        <bean class="org.springframework.retry.policy.SimpleRetryPolicy">
            <property name="maxAttempts" value="2" />
        </bean>
    </property>
</bean>


<rabbit:listener-container id="messageListenerContainer"
        connection-factory="connectionFactory" concurrency="1" acknowledge="auto" advice-chain="retryAdvice" >
    <rabbit:listener ref="listingsMessageListener" queue-names="${prosper.listing.phl.queue}" />
    <rabbit:listener ref="prospectsMessageListener" queue-names="${prosper.prospect.phl.queue}" />
</rabbit:listener-container>

1 个答案:

答案 0 :(得分:0)

我认为你应该设置spring.rabbitmq.listener.retry.enabled属性true。默认情况下,RabbitMQ不会重试失败的消息(假设失败是在消费者端)。

同样AmqpRejectAndDontRequeueException阻止您的邮件被重新排队。