@smpapas You can scale the ThreadPoolTaskExecutor to ensure you have an appropriate amount of threads to handle the incoming message rate. You can define a publish-subscribe channel that uses the thread pool and has a queue capacity. If that queue capacity is reached, the consumer thread will receive an exception attempting to put the message into that pubsub channel (from Spring Integration). You can issue a sleep or other logic to delay delivery of that message until the ThreadPool can catch up. The rejectedExecutionHandler is a handler for such logic. I simply tried to put the message back onto the channel for processing.
Here is an example of what I’ve done in the past and has worked for me.
<int:publish-subscribe-channel id="msg.service" task-executor="taskExecutor"/>
<beans:bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<beans:property name="corePoolSize" value="1" />
<beans:property name="maxPoolSize" value="${service.max-thread-count}" />
<beans:property name="queueCapacity" value="100" />
<beans:property name="rejectedExecutionHandler" ref="blockCallerExecutionPolicy" />
</beans:bean>