博客
关于我
Spring Cloud Stream:消费失败后的处理策略(一):自动重试
阅读量:87 次
发布时间:2019-02-26

本文共 1955 字,大约阅读时间需要 6 分钟。

Spring Cloud Stream??????????

????

????????????????????????????????Spring Cloud Stream????????????????????????????????????????????????????????????????

????

???????????????Spring Cloud Stream???????????????????????

@EnableBinding(TestApplication.TestTopic.class)@SpringBootApplicationpublic class TestApplication {    public static void main(String[] args) {        SpringApplication.run(TestApplication.class, args);    }}@RestControllerstatic class TestController {    @Autowired    private TestTopic testTopic;    @GetMapping("/sendMessage")    public String messageWithMQ(@RequestParam String message) {        testTopic.output().send(MessageBuilder.withPayload(message).build());        return "ok";    }}@Slf4j@Componentstatic class TestListener {    @StreamListener(TestTopic.INPUT)    public void receive(String payload) {        log.info("Received: " + payload);        throw new RuntimeException("Message consumer failed!");    }}interface TestTopic {    String OUTPUT = "example-topic-output";    String INPUT = "example-topic-input";    @Output(OUTPUT)    MessageChannel output();    @Input(INPUT)    SubscribableChannel input();}

????

????????????????????????

spring.cloud.stream.bindings.example-topic-input.destination=test-topicspring.cloud.stream.bindings.example-topic-output.destination=test-topic

????????localhost:8080/sendMessage?message=hello????????????????????????

2018-12-10 11:20:21.345 INFO ... Received: hello2018-12-10 11:20:22.350 INFO ... Received: hello2018-12-10 11:20:24.354 INFO ... Received: hello2018-12-10 11:20:54.651 ERROR ... Message consumer failed!

??????????3??

??????

??????Spring Cloud Stream???3???????????????

spring.cloud.stream.bindings.example-topic-input.consumer.max-attempts=1

????????????????????????0???????????????

????

??????????????????

????????????????????????????????????????

????????????

????????????????????????????????????????????????

????

????????????stream-exception-handler-1?????????????

转载地址:http://endz.baihongyu.com/

你可能感兴趣的文章
Objective-C实现alternate disjoint set不相交集算法(附完整源码)
查看>>
Objective-C实现An Armstrong number阿姆斯特朗数算法(附完整源码)
查看>>
Objective-C实现anagrams字谜算法(附完整源码)
查看>>
Objective-C实现ApproximationMonteCarlo蒙特卡洛方法计算pi值算法 (附完整源码)
查看>>
Objective-C实现area under curve曲线下面积算法(附完整源码)
查看>>
Objective-C实现arithmetic算术算法(附完整源码)
查看>>
Objective-C实现armstrong numbers阿姆斯壮数算法(附完整源码)
查看>>
Objective-C实现articulation-points(关键点)(割点)算法(附完整源码)
查看>>
Objective-C实现atoi函数功能(附完整源码)
查看>>
Objective-C实现average absolute deviation平均绝对偏差算法(附完整源码)
查看>>
Objective-C实现average mean平均数算法(附完整源码)
查看>>
Objective-C实现average median平均中位数算法(附完整源码)
查看>>
Objective-C实现average mode平均模式算法(附完整源码)
查看>>
Objective-C实现avl 树算法(附完整源码)
查看>>
Objective-C实现AvlTree树算法(附完整源码)
查看>>
Objective-C实现backtracking Jump Game回溯跳跃游戏算法(附完整源码)
查看>>
Objective-C实现BACKTRACKING 方法查找集合的幂集算法(附完整源码)
查看>>
Objective-C实现bailey borwein plouffe算法(附完整源码)
查看>>
Objective-C实现base64加密和base64解密算法(附完整源码)
查看>>
Objective-C实现base64加解密(附完整源码)
查看>>