[英]Spring Integration DSL: how to make single-threaded caching channel?
I have the following flow config: 我有以下流程配置:
@Bean
public IntegrationFlow setupDatabaseFlow() {
return IntegrationFlows.from(pubSubDatabaseRabbitOutput)
// WHAT CHANNEL
.handle((p, h) -> databaseActivator.recordToDatabase(p, h))
.get();
}
and I am willing to insert in "WHAT CHANNEL" place some channel, that is 我愿意在“ WHAT CHANNEL”中插入一些频道,即
What would be the best channel specification to use here? 在这里使用的最佳渠道规范是什么?
Not sure what is the use-case, but that can be achieved with the QueueChannel
and PollingConsumer
with the fixedDelay
policy. 不确定用例是什么,但是可以使用
QueueChannel
和PollingConsumer
和fixedDelay
策略来实现。
QueueChannel
uses queue buffer (persistent or in-memory) to keep messages until they are consumed. QueueChannel
使用队列缓冲区(持久性或内存中)来保留消息,直到消息被消耗为止。 A-la cache in your terms. 用您的术语表示的A-la缓存。
The PollingConsumer
does the poll from the queue using TaskScheduler
, therefore separate thread. PollingConsumer
使用TaskScheduler
从队列中进行轮询,因此使用单独的线程。
Using fixedDelay
policy you ensure that the next polling task won't start until the previous has been finished. 使用
fixedDelay
策略,可以确保fixedDelay
一个轮询任务完成之前不会启动下一个轮询任务。 Therefore single-threaded model. 因此是单线程模型。
If you don't like to sleep in between polling task, and end up with the event-driven model, you can use fixedDelay(-1)
, this way the next polling task won't sleep after the previous. 如果您不喜欢在轮询任务之间休眠,而最终遇到事件驱动的模型,则可以使用
fixedDelay(-1)
,这样,下一个轮询任务将不会在前一个轮询任务之后休眠。 The current polling task does block the thread until the value in the queue. 当前的轮询任务确实会阻塞线程,直到队列中的值为止。
UPDATE UPDATE
Some code on the matter: 关于此问题的一些代码:
.channel(c -> c.queue())
.<Object>handle((p, h) -> databaseActivator.recordToDatabase(p, h),
e -> e.poller(p -> p.fixedDelay(0).maxMessagesPerPoll(1)))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.