首页 > 解决方案 > Spring 集成事件监听器入站适配器

问题描述

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

所需的代码:

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

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

标签: javaspringspring-integrationevent-listenerspring-integration-dsl

解决方案


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

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

... 

 IntegrationFlows.from(applicationListener())

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


推荐阅读