重试兔子消息时记录消息 [英] logging messages on retry of rabbit message

查看:96
本文介绍了重试兔子消息时记录消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在应用程序中使用RabbitMQ将付款请求排队,并让另一个队列将结果发送回调用方.在这两种情况下,客户端都请求了将重试的重试策略,但是该策略将永久重试,但是会在每次重试中在日志中放置一些内容,例如第x次重试事务...",以便外部系统可以通过监视来检测备份的内容日志文件.

We're using RabbitMQ in our application to queue payment requests, and have another queue to send results back to the caller. In both cases, the client has requested a retry policy that will retry forever, but will put something in the log on each retry like "Retrying transaction for the xth time..." so that an external system can detect stuff backing up by monitoring the log file.

我正在这样创建侦听器容器:

I'm creating listener container thus:

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的重试逻辑中埋藏着一些现成的日志,可以在记录器配置中启用?

So the retry works flawlessly, but I can't find a hook to actually log anything on the retries. Is there something I'm missing? Is there a hook in there somewhere to execute something on the retry? Something I can subclass? Or is there some exsting logging buried within the retry logic in Spring that I can just enable in my logger config?

谢谢.

克里斯.

推荐答案

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

You can switch on DEBUG level for the org.springframework.retry.support.RetryTemplate category and you'll see in the logs something like:

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>

这篇关于重试兔子消息时记录消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆