spring-integration

Dynamically registering multiple flows and running in parallel


I am dynamically registering multiple IntegrationFlows:

private IntegrationFlowContext context;

context.registration(flow1()).register();
context.registration(flow1()).register();

IntegrationFlow flow1(){
   return IntegrationFlow.from(messageSource....)
   p-> p.poller(...
  .channel("outhannel")
  .get()
}

MessageSource<Object> messageSource() {
        JdbcPollingChannelAdapter adapter = ....
}

I need each of them to run in different thread , and write to same outChannel.

How to do that?

I know that inside each flow i can set: taskExecutor(...) on the poller, but as I understand it just each poller will run in multithread, but i need the flow (jdbcadapter) to run in a thread.


Solution

  • The poller functionality is already based on the TaskScheduler. So, your JdbcPollingChannelAdapter instances are going to be called from those scheduler's thread. You might consider to increase the pool size for default TaskScheduler in Spring Boot, which is 1 by default: https://docs.spring.io/spring-boot/reference/features/task-execution-and-scheduling.html.

    That taskExecutor() indeed can help you to shift scheduling work to a different thread. So, not clear what is your concern here then.