Spring - 如何从队列中读取多个消息并将它们批量保留

时间:2017-11-30 17:13:44

标签: java spring spring-integration solace

我试图通过批量读取队列中的消息来改善使用(Spring Integration + Solace消息传递系统)构建的系统的性能(让我们一次说50个)并持久保存它们进入DB(批量)。 当我使用以下配置在入站通道适配器中使用Spring Integration轮询器时:

<int:poller
    messages-per-poll="100"
    rate="1000"
/>

我有两个问题:

  1. 在ServiceActivator中,我仍然需要收到一条消息 time(ServiceActivator方法不允许使用方法声明) 列表&gt;参数

  2. 即使一次阅读1封邮件,我也无法将其收集到列表中 (由50)批量持续,因为可能只有40条消息 在队列上,我需要(无限地)等待另外10个 持续。

  3. 我尝试用com.solacesystems.jcsmp.FlowReceiver来解决这个问题,它有一个缺点,我无法收到邮件标题。

    你有什么建议?

1 个答案:

答案 0 :(得分:0)

Aggregator EIP适合您。它可以配置为将消息分组到50,例如Thread.currentThread.getId()作为相关键。而且它也可以通过事实来释放群体&#34;空&#34;来自AbstractMessageSourceAdvice.afterReceive()的消息:

/**
 * Subclasses can take actions based on the result of the poll; e.g.
 * adjust the {@code trigger}. The message can also be replaced with a new one.
 * @param result the received message.
 * @param source the message source.
 * @return a message to continue to process the result, null to discard whatever the poll returned.
 */
public abstract Message<?> afterReceive(Message<?> result, MessageSource<?> source);

因此,当结果为null时,您应触发MessageGroupStoreReaper以使聚合器中的非50个组过期。

请参阅Reference Manual

相关问题