简体   繁体   English

如何配置 Spring 云 Stream 发布者重试?

[英]How to configure Spring Cloud Stream publisher retries?

I am using the RabbitMQ binder.我正在使用 RabbitMQ 活页夹。

Spring Cloud Stream lets developers retry when exceptions happen as consuming messages. Spring Cloud Stream 允许开发人员在消费消息发生异常时重试。

Producers can fail when RabbitMQ connectivity has been lost.当 RabbitMQ 连接丢失时,生产者可能会失败。 How can we configure SCS so that it retries when any error occurs as producing messages?我们如何配置 SCS 以便在生成消息时发生任何错误时重试? Or is there a way to apply the circuit breaker there?或者有没有办法在那里应用断路器?

Thanks谢谢

You can use standard spring boot properties ( retry.enabled etc) - scroll down to rabbitmq - to configure retry on the producer side.您可以使用标准的 spring 引导属性retry.enabled等) - 向下滚动到 rabbitmq - 在生产者端配置重试。 The binder will wire a retry template into the outbound adapter's RabbitTemplate . binder 会将重试模板连接到出站适配器的RabbitTemplate

spring.rabbitmq.template.retry.enabled=false # Whether publishing retries are enabled.
spring.rabbitmq.template.retry.initial-interval=1000ms # Duration between the first and second attempt to deliver a message.
spring.rabbitmq.template.retry.max-attempts=3 # Maximum number of attempts to deliver a message.
spring.rabbitmq.template.retry.max-interval=10000ms # Maximum duration between attempts.
spring.rabbitmq.template.retry.multiplier=1 # Multiplier to apply to the previous retry interval.

This is the code in the binder...这是活页夹中的代码...

        if (rabbitProperties != null && rabbitProperties.getTemplate().getRetry().isEnabled()) {
            Retry retry = rabbitProperties.getTemplate().getRetry();
            RetryPolicy retryPolicy = new SimpleRetryPolicy(retry.getMaxAttempts());
            ExponentialBackOffPolicy backOff = new ExponentialBackOffPolicy();
            backOff.setInitialInterval(retry.getInitialInterval().toMillis());
            backOff.setMultiplier(retry.getMultiplier());
            backOff.setMaxInterval(retry.getMaxInterval().toMillis());
            RetryTemplate retryTemplate = new RetryTemplate();
            retryTemplate.setRetryPolicy(retryPolicy);
            retryTemplate.setBackOffPolicy(backOff);
            rabbitTemplate.setRetryTemplate(retryTemplate);
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为Spring-cloud-stream配置GlobalChannelInterceptor? - How to configure GlobalChannelInterceptor for spring-cloud-stream? Spring Cloud Stream 和@Publisher 注解的兼容性 - Spring Cloud Stream and @Publisher annotation compatiblity 如何使用 Openfeign 配置 Ribbon 来管理重试 - Spring? - How to configure Ribbon with Openfeign to manage retries - Spring? Spring 云 stream kafka 消费者错误处理和重试问题 - Spring cloud stream kafka consumer error handling and retries issues 在 Spring Cloud Stream 中为特定供应商配置轮询器 - Configure Poller for the specific supplier in Spring Cloud Stream 如何配置 DeadLetterPublisherRecoverer 以在 Spring Cloud Stream 批处理模式下将错误消息发送到 DLQ - How to configure DeadLetterPublisherRecoverer to send error messages to a DLQ in Spring Cloud Stream batch mode 在 Kafka 代理本身或通过 Spring Cloud Stream 配置主题 - Configure Topics in Kafka broker itself or via Spring Cloud Stream 具有自动配置的属性不适用于Spring Cloud Stream和Rabbitmq - Properties with auto configure not working on spring cloud stream and rabbitmq 如何配置Spring Cloud StreamBridge来生产Avro? - How to Configure Spring Cloud StreamBridge to produce Avro? 如何使用注解配置Spring Cloud AWS消息传递? - How to configure Spring Cloud AWS messaging with annotations?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM