【问题标题】:logging messages on retry of rabbit message在重试兔子消息时记录消息
【发布时间】:2014-10-09 16:41:59
【问题描述】:

我们在应用程序中使用 RabbitMQ 对支付请求进行排队,并使用另一个队列将结果发送回调用方。在这两种情况下,客户端都请求了一个重试策略,该策略将永远重试,但会在每次重试时在日志中添加一些内容,例如“第 x 次重试事务...”,以便外部系统可以通过监控检测备份的内容日志文件。

我正在创建侦听器容器:

public SimpleMessageListenerContainer paymentListenerContainer() {
    final SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
    container.setConnectionFactory(rabbitConnectionFactory());
    container.setQueues(paymentQueue());
    container.setMessageListener(cpmPaymentListener());
    container.setConcurrentConsumers(configurationService.getAmqpConcurrentConsumers());
    container.setMaxConcurrentConsumers(configurationService.getAmqpMaxConcurrentConsumers());
    container.setAdviceChain(new Advice[] { paymentRetryInterceptor() });
    return container;
}

并由此定义重试逻辑:

public RetryOperationsInterceptor paymentRetryInterceptor() {
    return RetryInterceptorBuilder.stateless()
            .maxAttempts(configurationService.getPaymentRetryMaxAttempts())
            .backOffOptions(configurationService.getPaymentRetryInitialInterval(), configurationService.getPaymentRetryMultiplier(), configurationService.getPaymentRetryMaxInterval()) // initialInterval, multiplier, maxInterval
            .build();
}

所以重试工作完美无缺,但我找不到一个钩子来实际记录重试的任何内容。有什么我想念的吗?那里有一个钩子可以在重试时执行某些操作吗?我可以子类化的东西?还是在 Spring 的重试逻辑中隐藏了一些现有的日志记录,我可以在我的记录器配置中启用这些记录?

谢谢。

克里斯。

【问题讨论】:

    标签: logging rabbitmq spring-amqp spring-retry


    【解决方案1】:

    您可以为 org.springframework.retry.support.RetryTemplate 类别打开 DEBUG 级别,您会在日志中看到如下内容:

    2014-10-09 20:18:51,126 DEBUG main [org.springframework.retry.support.RetryTemplate] - <Retry: count=0>
    2014-10-09 20:18:51,140 DEBUG main [org.springframework.retry.support.RetryTemplate] - <Checking for rethrow: count=1>
    2014-10-09 20:18:51,140 DEBUG main [org.springframework.retry.support.RetryTemplate] - <Retry: count=1>
    2014-10-09 20:18:51,141 DEBUG main [org.springframework.retry.support.RetryTemplate] - <Checking for rethrow: count=2>
    2014-10-09 20:18:51,141 DEBUG main [org.springframework.retry.support.RetryTemplate] - <Retry: count=2>
    2014-10-09 20:18:51,141 DEBUG main [org.springframework.retry.support.RetryTemplate] - <Checking for rethrow: count=3>
    2014-10-09 20:18:51,141 DEBUG main [org.springframework.retry.support.RetryTemplate] - <Retry failed last attempt: count=3>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-21
      • 2019-08-07
      • 1970-01-01
      • 2016-12-13
      • 2011-01-08
      • 2021-05-17
      • 2010-12-01
      • 1970-01-01
      相关资源
      最近更新 更多