【发布时间】: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