簡體   English   中英

Spring Cloud Stream發送到Kafka錯誤控制處理

[英]Spring Cloud Stream send to Kafka error control handling

如何捕獲寫入Kafka主題的錯誤?

import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Processor;
import org.springframework.messaging.Message;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Component;

import javax.xml.bind.JAXBException;

@Component
@EnableBinding(Processor.class)
public class Parser {

    @StreamListener(Processor.INPUT)
    @SendTo(Processor.OUTPUT)
    public String process(Message<?> input) {

        // do smth

        // how to catch an error if sending message to 'output' topic fails
    }

}

將生產者切換到同步模式。

spring.cloud.stream.kafka.bindings.output.producer.sync=true

接下來是什么? 任何例子? 擴展一些綁定impl,添加一些AOP魔法?

我認為你需要的是注冊一個KafkaProducerListener來處理你的情況下的錯誤場景,並使它在你的應用程序中作為bean使用。

有關KafkaProducerListener的更多信息,請點擊此處

另請注意,通常失敗的消息將在errorChannelerrorChannel ,並且通道名稱error 配置錯誤通道的destination名稱后,將發布所有錯誤消息: spring.cloud.stream.bindings.error.destination

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM