Search code examples
javaspringspring-integrationseda

Spring Integration and SEDA-like MessageChannels


Java 11 and Spring Integration 5.x here. I come from an Apache Camel background am trying to wire all of my channels together with whatever Spring Integration's equivalent of a SEDA Queue is. Currently I have all of my channels being defined with their own asynchronous task executor like so:

@Bean
public Executor channel1Executor() {

    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(corePoolSize);
    executor.setMaxPoolSize(maxPoolSize);
    executor.setQueueCapacity(queueCapacity);
    executor.setThreadNamePrefix("c1-executor");

    return executor;

}

@Bean
public Executor channel2Executor() {

    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(corePoolSize);
    executor.setMaxPoolSize(maxPoolSize);
    executor.setQueueCapacity(queueCapacity);
    executor.setThreadNamePrefix("c2-executor");

    return executor;

}

@Bean
public Executor channel3Executor() {

    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(corePoolSize);
    executor.setMaxPoolSize(maxPoolSize);
    executor.setQueueCapacity(queueCapacity);
    executor.setThreadNamePrefix("c3-executor");

    return executor;

}

@Bean
public MessageChannel channel1() {
    return MessageChannels.executor("c1", channel1Executor()).get();
}

@Bean
public MessageChannel channel2() {
    return MessageChannels.executor("c2", channel2Executor()).get();
}

@Bean
public MessageChannel channel3() {
    return MessageChannels.executor("c3", channel3Executor()).get();
}

Is this the standard way of wiring together channels asynchronously, SEDA-like? Or should I be using one (1) single async executor for all channels (1, 2 and 3)?


Solution

  • According to the link from that Apache Camel page we got this:

    The staged event-driven architecture (SEDA) refers to an approach to software architecture that decomposes a complex, event-driven application into a set of stages connected by queues.

    "By queues"

    So, consider to really use a QueueChannel instead: https://docs.spring.io/spring-integration/docs/current/reference/html/core.html#channel-implementations-queuechannel

    A dedicated TaskExecutor for each channel is also not a requirement from the framework perspective. It is really up to your application logic to decide if it is OK to stay with a single shared one or have per channel to distribute tasks for some reason.