Reputation: 354
I have a simple, working Spring Integration application the moves messages from an inbound RabbitMQ gateway, through a handler chain and into a MongoDB database. When I changed from a direct channel to an executor channel, I started getting subscriber errors. Watching things in the debugger I saw that after I set up the ExecutorChannel bean, the onInit() method gets triggered and resets everything to default values. I cannot figure out why the code would be structured to do this? I looked at DirectChannel.onInit() and it only modifies things if values have not previously been set. Any ideas? I am using 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
Upvotes: 1
Views: 119
Reputation: 4116
When you create channels using XML application context, you first define the channel and after you use it in an EIP pattern:
<int:channel id="directChannel"/>
<int:service-activator input-channel="directChannel"/>
This allows in my opinion a better separation of concern. Same pattern must be used with java configuration, first declare your channel then declare MessageHandlerChain
and subscribe to the channel
@Bean
ExecutorChannel uploadChannel() {
def bean = new ExecutorChannel( Executors.newCachedThreadPool() )
bean
}
@Bean
MessageHandlerChain uploadMessageHandlerChain(){
def uploadMessageHandlerChain = new MessageHandlerChain()
uploadChannel().subscribe(uploadMessageHandlerChain)
uploadMessageHandlerChain
}
Upvotes: 1