Spring Integration – 检查尚未添加的消息的 ReleaseStrategy

huangapple go评论79阅读模式
英文:

Spring Integration - ReleaseStrategy that looks at messages that weren't yet added

问题

我有一些以组的形式获取到系统中的消息(假设每组有50条),需要按照AGGREGATION_ID进行分组,形成消息列表,并将其进一步发送到流程中。

我可以使用correlationStrategy根据该ID进行聚合,但我需要知道何时释放聚合后的消息。在ReleaseStrategy中,我只能查看已添加到聚合中的消息,但我需要知道在获取到的50条消息组中没有更多具有相同AGGREGATION_ID的消息时,何时发送该组。我该如何做到这一点?

英文:

I have messages that are fetched to the system in groups (let's say 50), need to be grouped by AGGREGATION_ID into lists of messages and send further into the flow.

I can use correlationStrategy to aggregate with that id, but I need to know when to release the aggregated message. In ReleaseStrategy I can only look at the messages already added to the aggregate, but I need to know when there's no more messages in the fetched group of 50 with the same AGGREGATION_ID to know when to send the group. How can I do that?

答案1

得分: 2

一个ReleaseStrategy可以是任何具有对整个应用程序上下文完全访问权限的bean。如果您有一些地方在聚合之前存储这些消息,您肯定可以从自定义的ReleaseStrategy实现中查看该位置。

另一方面,我建议您查看聚合器的groupTimeout选项:https://docs.spring.io/spring-integration/docs/5.3.0.M4/reference/html/message-routing.html#agg-and-group-to。因此,根据正常行为,您的组将根据预期的大小50进行聚合,但是当一段时间内没有新的组消息时,组将以迄今为止的任何内容释放。您还可以将groupTimeout配置为SpEL表达式,因此也可以访问应用程序上下文。

英文:

A ReleaseStrategy could be any bean with a full access to the whole application context. If you have some place where you store those messages before aggregation, you definitely can take a look into that place from a custom ReleaseStrategy implementation.

On the other hand I would suggest to take a look into the groupTimeout option of an aggregator: https://docs.spring.io/spring-integration/docs/5.3.0.M4/reference/html/message-routing.html#agg-and-group-to. So, with the normal behavior your groups are going to be gathered according an expected size of 50, but when there is no new messages for the group during some time, a group is going to be released with whatever is there so far. You also can configure that groupTimeout as a SpEL expression, so there is an access to application context, too.

huangapple
  • 本文由 发表于 2020年4月6日 17:22:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/61056592.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定