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

你可能感兴趣的文章
OSPF 四种路由类型:Intra Area、Inter Area、第一、二类外部路由
查看>>
OSPF 学习
查看>>
OSPF 支持的网络类型:广播、NBMA、P2MP和P2P类型
查看>>
OSPF 概念型问题
查看>>
OSPF 的主要目的是什么?
查看>>
OSPF5种报文:Hello报文、DD报文、LSR报文、LSU报文和LSAck报文
查看>>
SQL Server 存储过程分页。
查看>>
OSPFv3:第三版OSPF除了支持IPv6,还有这些强大的特性!
查看>>
OSPF不能发现其他区域路由时,该怎么办?
查看>>
OSPF两个版本:OSPFv3与OSPFv2到底有啥区别?
查看>>
SQL Server 存储过程
查看>>
OSPF在什么情况下会进行Router ID的重新选取?
查看>>
OSPF在大型网络中的应用:高效路由与可扩展性
查看>>
OSPF太难了,这份OSPF综合实验请每位网络工程师查收,周末弯道超车!
查看>>
OSPF技术入门(第三十四课)
查看>>
OSPF技术连载10:OSPF 缺省路由
查看>>
OSPF技术连载11:OSPF 8种 LSA 类型,6000字总结!
查看>>
OSPF技术连载12:OSPF LSA泛洪——维护网络拓扑的关键
查看>>
OSPF技术连载13:OSPF Hello 间隔和 Dead 间隔
查看>>
OSPF技术连载14:OSPF路由器唯一标识符——Router ID
查看>>