博客
关于我
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 基础 - Day 5 Learning Note - 模块 之 标准库:time (1)
查看>>
Python 基础一
查看>>
Python 基础知识点整理与分享,期盼你的交流!
查看>>
python 基础第七篇
查看>>
Python编程:Tkinter图形界面设计(1)
查看>>
Python 基础语法:None
查看>>
Python 基础语法:基本数据类型(一)
查看>>
python编程读取写入excel_Python读取txt内容写入xls格式excel中的方法
查看>>
Python 基础语法:基本数据类型(字典)
查看>>
Python 基础语法:基本数据类型(字符串)
查看>>
Python 基础语法:基本数据类型(集合)
查看>>
Python编程的终极十大工具
查看>>
python 堆排序
查看>>
python编程方式之一-函数式编程
查看>>
python 复习计划
查看>>
Python 多处理 apply_async 永远不会在 Windows 7 上返回结果
查看>>
Python 多处理 Numpy 随机
查看>>
Python 多处理 >= 125 列表永远不会完成
查看>>
Python 多处理:在第一个子错误时中止映射
查看>>
Python 多处理不断产生 pythonw.exe 进程而不做任何实际工作
查看>>