【问题标题】:Spring Cloud Stream: Global errorChannel does not workSpring Cloud Stream:全局errorChannel不起作用
【发布时间】:2019-06-20 21:05:14
【问题描述】:

根据这个documentation,应该可以订阅Spring Integration提供的全局错误通道——“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;
        }
    }
}

我的水槽

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

【问题讨论】:

    标签: spring-boot spring-integration messaging spring-cloud-stream


    【解决方案1】:

    没有任何问题,它按预期工作。来自文档:“订阅名为 input 的通道的 handle(..) 方法会引发异常。假设还有一个错误通道 input.myGroup.errors 的订阅者,所有错误消息都由此处理订阅者。” 因此,这意味着您的错误由绑定特定错误处理程序 (mySink.mySink-group.errors) 或全局 (errorChannel) 处理。

    https://cloud.spring.io/spring-cloud-static/spring-cloud-stream/2.2.0.RELEASE/spring-cloud-stream.html#spring-cloud-stream-overview-error-handling

    【讨论】:

    • 谢谢!没有得到默认情况下全局和特定处理程序不能一起工作的观点。
    • 没关系,我们会尝试更新文档以使其更清晰
    猜你喜欢
    • 1970-01-01
    • 2021-06-03
    • 1970-01-01
    • 2019-06-04
    • 1970-01-01
    • 2016-09-09
    • 2021-12-13
    • 2020-03-08
    • 2020-08-21
    相关资源
    最近更新 更多