I have been reading the spring-cloud-stream documentation, specifically error handling:
@StreamListener(Sink.INPUT) // destination name 'input.myGroup'
public void handle(Person value) {
throw new RuntimeException("BOOM!");
}
@ServiceActivator(inputChannel = Processor.INPUT + ".myGroup.errors") //channel name 'input.myGroup.errors'
public void error(Message<?> message) {
System.out.println("Handling ERROR: " + message);
}
Regarding to what the documentation says about it, when you want to catch the errors, you might want to use @ServiceActivator
. This does not have an associated external destination.
The use of @StreamListener annotation is intended specifically to define bindings that bridge internal channels and external destinations. Given that the destination specific error channel does NOT have an associated external destination, such channel is a prerogative of Spring Integration (SI). This means that the handler for such destination must be defined using one of the SI handler annotations (i.e., @ServiceActivator, @Transformer etc.).
I have also followed this whole thread about error channel creation, where it confirms that having a @ServiceActivator
annotation will not create an external destination to propagate the errors.
I have a use case where an external listener process will be consuming the errors published into a particular Kafka error-topic. Based on this, I have the following questions,
- What does specifically do
@ServiceActivator
or wthat is the feature that this particular annotation provide? - What would be a good approach to propagate the errors to an external destination? (Let's say for example, a Kafka topic).
- Is publishing the error into an external destination in order to be consumed later on a good pattern ?