我有一个简单的,有效的Spring Integration应用程序,它将来自入站RabbitMQ网关的消息通过处理程序链移动到MongoDB数据库中。当我从直接通道更改为执行程序通道时,我开始收到订户错误。在调试器中观察事物我看到在设置ExecutorChannel bean之后,onInit()方法被触发并将所有内容重置为默认值。我无法弄清楚为什么代码会被构造成这样做?我查看了DirectChannel.onInit(),它只修改了以前没有设置过值的东西。有任何想法吗?我正在使用Spring Integration 4.1.2。
// from
@Bean
DirectChannel uploadChannel( MessageHandlerChain uploadMessageHandlerChain ) {
def bean = new DirectChannel()
bean.subscribe( uploadMessageHandlerChain )
bean
}
// to
@Bean
ExecutorChannel uploadChannel( MessageHandlerChain uploadMessageHandlerChain ) {
def bean = new ExecutorChannel( Executors.newCachedThreadPool() )
bean.subscribe( uploadMessageHandlerChain )
bean
}
org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers
答案 0 :(得分:1)
使用XML应用程序上下文创建频道时,首先定义频道,然后在EIP模式中使用它:
<int:channel id="directChannel"/>
<int:service-activator input-channel="directChannel"/>
在我看来,这可以更好地分离关注点。必须在java配置中使用相同的模式,首先声明您的频道然后声明MessageHandlerChain
并订阅频道
@Bean
ExecutorChannel uploadChannel() {
def bean = new ExecutorChannel( Executors.newCachedThreadPool() )
bean
}
@Bean
MessageHandlerChain uploadMessageHandlerChain(){
def uploadMessageHandlerChain = new MessageHandlerChain()
uploadChannel().subscribe(uploadMessageHandlerChain)
uploadMessageHandlerChain
}