1
votes

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,

  1. What does specifically do @ServiceActivator or wthat is the feature that this particular annotation provide?
  2. What would be a good approach to propagate the errors to an external destination? (Let's say for example, a Kafka topic).
  3. Is publishing the error into an external destination in order to be consumed later on a good pattern ?
1

1 Answers

2
votes

@ServiceActivator would be specifically for internal error handling (i.e., by the same application). For cases where you want errors to be sent to a Kafka topic so they can be consumed by an external consumer you should use the DLQ. You can find more details here https://docs.spring.io/spring-cloud-stream/docs/Elmhurst.RELEASE/reference/htmlsingle/#kafka-dlq-processing

Please let us know if you still have more questions