I am having an rest post endpoint which consumes data and writes to Kafka using Spring Cloud Stream Kafka Binder. Right now we are not having any error handling in place. But we want to make this endpoint fault tolerant by adding an extra check whenever data is not written to Kafka. We intend to send an exception info object when data is not written to Kafka. I am trying to achieve this using global errors in this way
@ServiceActivator(inputChannel = "errorChannel")
public void handle(final ErrorMessage em) {
logger.error("encountered exception" + em.getOriginalMessage().toString());
throw new RuntimeException(em.getOriginalMessage().toString);
}
My doubt is two fold:
- Is this the correct way to handle exceptions when the data we write to Kafka fails.
- Is this handle method called whenever data write is failed and is this change propagated to system level error handling.
If there is another process please suggest. We are currently exploring application level error handling and global level error handling. System level error handling is off the table for now. Thanks in advance.