0

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))
}    

 
Gary Russell
  • 166,535
  • 14
  • 146
  • 179
joe
  • 1

1 Answers1

0

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.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • Thank you .I have tried the above suggestions already .But didnt' able to produce the expected result .Its only working when kafka broker is down then errorChannel method is called .I wanted to send it to some other topic when a persistent exception occurs .I have added spring.cloud.stream.bindings.output.producer.errorChannelEnabled =true and spring.cloud.stream.kafka.bindings.output.producer.configuration.sync=true ,spring.cloud.stream.bindings.error.destination=sometopic .But its not working and I dint get the expected output . So how can I send to some other topic for a persistent errors – joe Sep 16 '22 at 03:34
  • Post an [MCRE](https://stackoverflow.com/help/minimal-reproducible-example) someplace so we can see what you are doing wrong. – Gary Russell Sep 19 '22 at 13:29