How would one utilize poison pill to stop message handlers (and message suppliers) with spring-integration?
I have a setup of N producers (subclassed Supplier) and M consumers (subclasses GenericHandler). They are connected via unbounded queue.
Producers should send K messages each, then send poison pill (I think each producer should send M/N poison pills, that is).
I would like then, to stop producers altogether (they are controlled by TaskExecutor)
@Bean(name = "supplierExecutor")
Executor supplierExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(x);
executor.setMaxPoolSize(y);
executor.setKeepAliveSeconds(0);
executor.setQueueCapacity(z);
executor.setThreadNamePrefix("supplier-");
executor.initialize();
return executor;
}
Also, I would like to stop consumers altogether, but gracefully. (They are controlled by their own TaskScheduler)
@Bean(name = "consumerScheduler")
TaskScheduler taskScheduler() {
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
taskScheduler.setPoolSize(a);
taskScheduler.setThreadNamePrefix("temp-consumer");
taskScheduler.initialize();
taskScheduler.setWaitForTasksToCompleteOnShutdown(true);
return taskScheduler;
}
Right now, in my supplier get()
method, I have the following snippet
public Foo get() {
if (reachedMaxSendLimit()) {
incrementMsgSentCount();
return POISON_PILL;
} else if (surpassedMaxSentLimit()) {
return null;
} else {
return handlePayload(payload);
}
}
Is there a well-defined way to achieve the behaviour I'm trying to accomplish? I am aware how I'd do it without spring with regular Runnables, but I'm a bit clueless here.