【问题标题】:Spring Integration Event Listener Inbound AdapterSpring 集成事件监听器入站适配器
【发布时间】:2018-10-29 15:16:31
【问题描述】:

我有一个问题,我想在 spring 集成中使用 dsl 实现一个输入适配器,作为事件侦听器并将消息从该事件侦听器重定向到通道。

所需代码:

@Bean
public IntegrationFlow listenerFlow() {
    return IntegrationFlows.from(InputAdapterListener.listen())
            .channel("ChannelXYZ")
            .get();
}

有人可以向我解释一下 InputAdatperListener 类的实现是什么,以支持这样的行为,或者在哪里可以找到一些示例?

【问题讨论】:

    标签: java spring spring-integration event-listener spring-integration-dsl


    【解决方案1】:

    spring-integration-event 中有一个 ApplicationEventListeningMessageProducer 供您在 from() 配置中使用:

     private ApplicationListener<?> applicationListener() {
            ApplicationEventListeningMessageProducer producer = new ApplicationEventListeningMessageProducer();
            producer.setEventTypes(TestApplicationEvent1.class);
            producer.setOutputChannel(resultsChannel());
            return producer;
        }
    
    ... 
    
     IntegrationFlows.from(applicationListener())
    

    这个会自动注册为一个bean。

    【讨论】:

    • 但是,如果您不是在谈论 Spring Application 事件,而是在谈论其他一些事件源,那么您可以扩展 MessageProducerSupport 并调用 sendMessage()
    猜你喜欢
    • 2014-05-31
    • 1970-01-01
    • 2011-08-29
    • 1970-01-01
    • 1970-01-01
    • 2015-03-21
    • 2015-07-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多