我从不同线程的多个来源接收数据。计划将数据传递到单个通道,然后单独的线程将处理来自此通道的数据。我的上下文如下
<task:executor id="singleThreadedExecutor" pool-size="1" />
<int:channel id="entryChannel">
<int:dispatcher task-executor="singleThreadedExecutor"/>
</int:channel>
<int:header-enricher input-channel="entryChannel" output-channel="processDataChannel">
<int:error-channel ref="exceptionHandlerChannel" overwrite="true" />
<int:header name="systemtime" expression="T(java.lang.System).currentTimeMillis()" />
<int:header name="nanotime" expression="T(java.lang.System).nanoTime()" />
</int:header-enricher>
我想在数据到达后立即处理。在单独的线程中,当数据到达的速度比数据处理时间快得多时,我担心。 从文档中,在entryChannel上调用Send应该立即返回。 调度员是否有内部排队机制来确保数据被移交给渠道?我们如何确保数据一到达就立即交付? 有兴趣了解我们需要在单独的线程中处理数据的最佳实践,一旦到达,就在SI?
答案 0 :(得分:1)
首先,你的问题在这里:
<task:executor id="singleThreadedExecutor" pool-size="1" />
与发件人无关,只有一个Thread
能够从entryChannel
获取邮件。只有当它是免费的并准备好从你提出的要求时才会这样做。但在你的情况下,它忙于处理第一个消息,然后是第二个消息,依此类推。一个接一个,一次只有一个,因为它是一个单一的线程。
您只需要增加池大小(例如10)以允许从该通道分发多个并行线程的消息。
关于第二个问题:Back Pressure。
答案 1 :(得分:0)
任务执行程序本身保存队列中的任务(调用订阅的端点),因此,是的,调用者立即退出(只要队列中有空间,对于您的配置总是如此)