本文共 1955 字,大约阅读时间需要 6 分钟。
????????????????????????????????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/