![](/img/trans.png)
[英]Error handling in Spring Cloud Stream Kafka in Batch mode
[英]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的更多信息,請點擊此處
另請注意,通常失敗的消息將在errorChannel
上errorChannel
,並且通道名稱error
。 配置錯誤通道的destination
名稱后,將發布所有錯誤消息: spring.cloud.stream.bindings.error.destination
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.