Handle Spring cloud stream kafka producer persistent exception

Viewed 26

I am working on spring cloud stream and kafka binder for event driven application(spring cloud stream annotation is using)
I was able to handle exception at consumer side using dead letter queue .But couldn't find out any relevant document for handling persistent exception at producer side. ie how can we handle if serialization /Size too large kind of exception(Persistent exception) occur while sending messages. I wanted to handle if error occur at the time of sending messages and that cant be recovered. Is there any mechanism. Please advice I am using below code

MessageChannel messageChannel;    
public void sendMessage(){
    messageChannel.send(new GenericMessage<>(message))
}    

 
1 Answers

See the documentation;

sync

https://docs.spring.io/spring-cloud-stream/docs/current/reference/html/spring-cloud-stream-binder-kafka.html#kafka-producer-properties

errorChannelEnabled

https://docs.spring.io/spring-cloud-stream/docs/current/reference/html/spring-cloud-stream.html#_producer_properties

you can either set sync to true and any exceptions will be thrown on the calling thread, or you can enable the error channel and an async message will be sent to that; you can also configure the recordMetadataChannel to get messages for successful sends.

When using async sends, certain exceptione (e.g. serialization) will still be thrown on the calling hread.

Related