Spring Cloud Stream:全局 errorChannel 不起作用
Spring Cloud Stream: Global errorChannel does not work
根据此documentation,应该可以订阅 Spring 集成提供的全局错误通道 - "errorChannel".
在我非常简单的情况下它不起作用:
申请:
@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();
}
属性
spring.rabbitmq.host=192.168.0.100
spring.cloud.stream.bindings.inputOne.destination=mySink
spring.cloud.stream.bindings.inputOne.group=mySink-group
特定于目标的处理程序有效 (mySink.mySink-group.errors),但从未调用其他两个处理程序。
这里有什么问题?
尝试使用 Spring Boot 2.1.6
没有任何问题,一切正常。来自文档:"The handle(..) method, which subscribes to the channel named input, throws an exception. Given there is also a subscriber to the error channel input.myGroup.errors all error messages are handled by this subscriber." 所以,这意味着您的错误是由绑定特定错误处理程序(mySink.mySink-group.errors
)或全局(errorChannel
).
根据此documentation,应该可以订阅 Spring 集成提供的全局错误通道 - "errorChannel".
在我非常简单的情况下它不起作用:
申请:
@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();
}
属性
spring.rabbitmq.host=192.168.0.100
spring.cloud.stream.bindings.inputOne.destination=mySink
spring.cloud.stream.bindings.inputOne.group=mySink-group
特定于目标的处理程序有效 (mySink.mySink-group.errors),但从未调用其他两个处理程序。
这里有什么问题?
尝试使用 Spring Boot 2.1.6
没有任何问题,一切正常。来自文档:"The handle(..) method, which subscribes to the channel named input, throws an exception. Given there is also a subscriber to the error channel input.myGroup.errors all error messages are handled by this subscriber." 所以,这意味着您的错误是由绑定特定错误处理程序(mySink.mySink-group.errors
)或全局(errorChannel
).