如何配置 Spring Cloud Stream 发布者重试? | 珊瑚贝

How to configure Spring Cloud Stream publisher retries?


我正在使用 RabbitMQ binder。

Spring Cloud Stream 允许开发人员在消费消息发生异常时重试。

当 RabbitMQ 连接丢失时,生产者可能会失败。我们如何配置 SCS 以便在生成消息时发生任何错误时重试?或者有没有办法在那里应用断路器?

谢谢


您可以使用标准的 Spring Boot 属性(retry.enabled 等)——向下滚动到 rabbitmq——在生产者端配置重试。绑定器会将重试模板连接到出站适配器的 RabbitTemplate.

1
2
3
4
5
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.

这是活页夹中的代码…

1
2
3
4
5
6
7
8
9
10
11
12
        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);
        }

来源:https://www.codenong.com/58150192/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_8774.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?