Java Spring—如何从队列中读取多条消息并将其批量持久化
我试图通过批量读取队列中的消息(一次读取50条)并将它们持久化到数据库中(批量),来提高使用(Spring集成+Solace消息传递系统)构建的系统的性能。 当我在入站通道适配器中使用具有以下配置的Spring集成轮询器时:Java Spring—如何从队列中读取多条消息并将其批量持久化,java,spring,spring-integration,solace,Java,Spring,Spring Integration,Solace,我试图通过批量读取队列中的消息(一次读取50条)并将它们持久化到数据库中(批量),来提高使用(Spring集成+Solace消息传递系统)构建的系统的性能。 当我在入站通道适配器中使用具有以下配置的Spring集成轮询器时: 我有两个问题: 在ServiceActivator中,我仍然需要一次接收一条消息 时间(ServiceActivator方法不允许使用 列表>参数 即使一次阅读一条信息,我也无法将它们收集到列表中 (按50)以批量保留,因为可能只有40条消息 在队列中,我需要(无限地)
我有两个问题:
你有什么建议?聚合器EIP是为你准备的。它可以配置为将消息分组到
50
,比如通过Thread.currentThread.getId()
作为相关键。它还可以通过AbstractMessageSourceAdvice.afterReceive()
通过事实“空”消息释放组:
/**
*子类可以根据轮询结果采取操作;例如。
*调整{@code trigger}。该消息也可以替换为新消息。
*@param result接收到的消息。
*@param source消息源。
*@return a message继续处理结果,null放弃轮询返回的任何内容。
*/
接收后的公共摘要消息(消息结果、消息源);
因此,当结果为null
时,您应该触发MessageGroupStoreReaper
使聚合器中的非50个组过期
请参阅。聚合器EIP是为您准备的。它可以配置为将消息分组到
50
,比如通过Thread.currentThread.getId()
作为关联键。它还可以通过AbstractMessageSourceAdvice.afterReceive()通过事实“空”消息释放组:
/**
*子类可以根据轮询结果采取操作;例如。
*调整{@code trigger}。该消息也可以替换为新消息。
*@param result接收到的消息。
*@param source消息源。
*@return a message继续处理结果,null放弃轮询返回的任何内容。
*/
接收后的公共摘要消息(消息结果、消息源);
因此,当结果为null
时,您应该触发MessageGroupStoreReaper
使聚合器中的非50个组过期
请参阅。谢谢您的快速回答!谢谢您的快速回答!
<int:poller
messages-per-poll="100"
rate="1000"
/>
/**
* 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);