博客
关于我
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/

你可能感兴趣的文章
python基础篇(14):多态
查看>>
python基础篇(13):类型注解
查看>>
python基础篇(12):继承
查看>>
python基础篇(11):封装
查看>>
python基础篇(10):自定义包
查看>>
python基础篇(10):类、对象与构造方法
查看>>
python系列【仅供参考】:python测试javaSDK总结
查看>>
python系列【仅供参考】:python斗地主
查看>>
Python基础教程(第2版 修订版) pdf
查看>>
python基础实践(四)
查看>>
Python基础学习笔记(九)常用数据类型转换函数
查看>>
Python基础学习参考(五):字符串和编码
查看>>
Python基础学习
查看>>
python基础变量之---集合
查看>>
python基础变量之---字典
查看>>
python基础变量之---列表
查看>>
python基础变量之---元组
查看>>
python基础内容_Python基础入门必须了解的
查看>>
Python基础之面向对象2(封装)
查看>>
Python基础之给函数增加元信息
查看>>