According to this documentation, it should be possible to subscribe to global error channel provided by Spring Integration - "errorChannel".
In my very simple case it does not work:
Application:
@SpringBootApplication
@EnableBinding({MySink.class})
public class LoggingConsumerApplication {
public static void main(String[] args) {
SpringApplication.run(LoggingConsumerApplication.class, args);
}
@StreamListener(target = MySink.INPUT_ONE)
public void handle(Person person) {
System.out.println("Received: " + person);
if(StringUtils.isEmpty(person.getName())){
throw new RuntimeException("Wrong person name!");
}
}
@ServiceActivator(inputChannel = "mySink.mySink-group.errors")
public void error(Message<?> message) {
System.out.println("Handling ERROR: " + message);
}
@ServiceActivator(inputChannel = "errorChannel")
public void errorGlobal(ErrorMessage message) {
System.out.println("Handling ERROR GLOBAL SA: " + message);
}
@StreamListener("errorChannel")
public void errorGlobalListener(ErrorMessage message) {
System.out.println("Handling ERROR GLOBAL Listener: " + message);
}
public static class Person {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String toString() {
return this.name;
}
}
}
MySink
public interface MySink {
/**
* Input channel name.
*/
String INPUT_ONE = "inputOne";
/**
* @return input channel.
*/
@Input(MySink.INPUT_ONE)
SubscribableChannel inputOne();
}
properties
spring.rabbitmq.host=192.168.0.100
spring.cloud.stream.bindings.inputOne.destination=mySink
spring.cloud.stream.bindings.inputOne.group=mySink-group
The destination-specific handler works (mySink.mySink-group.errors), but two other handlers never get called.
What is wrong here?
Tried with Spring Boot 2.1.6