Search code examples
spring-integrationeip

Competing Consumers


I want to configure a spring integration application so that if I put a number of tasks, each represented by one message, on a channel then one of a group of endpoints will pick the next task and process it. This would entail some thread pool executor service I guess.


Solution

  • Yes, use a dispatcher + task executor with the channel (aka ExecutorChannel). That way any endpoint (e.g. service-activator) consuming from the channel will be invoked asynchronously using dispatcher's thread pool.

    In the following example, any messages landing on channel channel01 will be consumed by the jobLauncher service within one of the taskExecutor threads.

    <int:channel id="channel01">
        <int:dispatcher task-executor="taskExecutor">
    </int:channel>
    
    <task:executor id="taskExecutor" pool-size="2"/>
    
    <int:service-activator input-channel="channel01" ref="jobLauncher">