Search code examples
springspring-bootspring-integrationspring-cloud-stream

Integration flow with PollableChannel in Spring Cloud Stream application causes scheduled tasks to be not triggered anymore


We're having a Spring Cloud Stream application with some scheduled tasks and added a new producer by adding a Supplier bean. The Supplier gets its input from a PollableChannel.

Since we've introduced the PollableChannel, the scheduled tasks are not fired by its cron expression anymore, as long no messages are present in the PollableChannel.

Its a Spring Boot 3.0.5 application with Spring Cloud Stream 2022.0.1.

I've provided a demo application on Github: https://github.com/sbillmaier/supplierAndTaskScheduler.git

As long the MessageSourceconfigured in EventFlowConfig returns null, the scheduled task ScheduledTask.doScheduled() is not fired anymore.

I've expected that the scheduled task is fired based on its cron even if there are no messages in the PollableChannel.

The current workaround is to define a custom TaskScheduler in SchedulingConfig.

What are the inner workings in Spring Boot/Spring Integration/Spring Cloud Stream causing this? Is this a possible bug, that the autoconfigured TaskScheduler is somehow "disabled"?


Solution

  • Your observation is correct. The auto-configured TaskScheduler comes with a single thread in its pool: https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#features.task-execution-and-scheduling.

    So, to mitigate the problem with your current versions, you need to increase that spring.task.scheduling.pool.size configuration property value. I believe it is exactly what you do with your custom TaskScheduler.

    In the latest Spring Integration version we did some further mitigation to not block on those queues indefinitely: https://github.com/spring-projects/spring-integration/wiki/Spring-Integration-6.0-to-6.1-Migration-Guide