Spring集成和类似SEDA的MessageChannel

blpfk2vs  于 2023-04-19  发布在  Spring
关注(0)|答案(1)|浏览(125)

Java 11和Spring Integration 5.x在这里。我来自Apache Camel背景,正在尝试将我所有的通道与Spring Integration的SEDA Queue等价物连接在一起。目前我有所有我的通道都定义有自己的异步任务执行器,如下所示:

@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();
}

这是异步连接通道的标准方式吗,类似于SEDA?或者我应该为所有通道(1,2和3)使用一个(1)异步执行器?

kupeojn6

kupeojn61#

根据Apache Camel页面的链接,我们得到了这个:
阶段式事件驱动架构(SEDA)是指将复杂的事件驱动应用程序分解为一组通过队列连接的阶段的软件架构方法。
“按队列”
因此,考虑真正使用QueueChannel:https://docs.spring.io/spring-integration/docs/current/reference/html/core.html#channel-implementations-queuechannel
从框架的Angular 来看,每个通道都有一个专用的TaskExecutor也不是必需的。实际上,由应用程序逻辑来决定是否可以保留单个共享通道,或者出于某种原因让每个通道分配任务。

相关问题