简体   繁体   English

Spring集成中分组和忽略消息

[英]grouping and disregarding messages in spring integration

I have a spring integration application that deals with different trade types in the database which I transform, filter and route to it's appropriate corresponding tradeEventChannel我有一个 spring 集成应用程序,它处理数据库中的不同交易类型,我将其转换、过滤并路由到相应的tradeEventChannel

New RowId->[GateAway]---->|======|----->Transformer->|======|------>Filter->|======|--->Router|======|--->repoTradeChannel

For one specific trade event type (repoTradeChannel), there are two possible cases:对于一种特定的交易事件类型 (repoTradeChannel),有两种可能的情况:

  1. user trades an open repo trade, this translates into one repo (open message) TradeEvent that should be routed to repoTradeChannel for processing.用户交易一个开放的回购交易,这转化为一个回购(开放消息) TradeEvent ,应该路由到repoTradeChannel进行处理。 When the trade is termed (hours, days or weeks later), a second messages (the term message) is received and that should also be processed .当交易被称为(数小时、数天或数周后)时,会收到第二条消息(术语消息)并且也应该对其进行处理
  2. user trades an term repo trade, this translates into two repo in the database (open and term message) TradeEvent .用户交易一个期限回购交易,这转化为数据库中的两个回购(开放和期限消息) TradeEvent However, only one should be routed to repoTradeChannel for processing as the second one causes issues.但是,只有一个应该路由到repoTradeChannel进行处理,因为第二个会导致问题。 The second one is received into the channel almost lets say within 3 minutes.第二个被接收到频道几乎可以说在 3 分钟内。

In both of the above cases, the TradeEvent / message can be grouped by id and other properties on the TradeEvent class.在上述两种情况下,可以通过TradeEvent类上的id和其他属性对TradeEvent / message进行分组。

My question is, can I use an aggregator to group the messages that come in the second case and disregard the second one?我的问题是,我可以使用aggregator对第二种情况下的消息进行分组而忽略第二种情况吗? I can look at for example the id or action fields to determine which is not acceptable.我可以查看例如idaction字段来确定哪个是不可接受的。 In the second case, the message/event is received within a few minutes, whereas in the first case the second message (term message) can be delayed, hours, days, or weeks.在第二种情况下,消息/事件会在几分钟内收到,而在第一种情况下,第二条消息(术语消息)可能会延迟数小时、数天或数周。

Is there strategy I can use to handle these cases at aggregation as I cannot stop the incoming messages and filter.是否有策略可以用来在聚合时处理这些情况,因为我无法停止传入的消息和过滤器。 I need to rely on grouping, then determining that the second message is not useful in the second case.我需要依靠分组,然后确定第二条消息在第二种情况下没有用。

what would the implementation look like?实现会是什么样子? Should I be using a different strategy like caching instead?我应该改用缓存等不同的策略吗?

In summary, the issue is really how do I differentiate the term message that is received in case 1 vs case 2, where case 2 one should be suppressed.总之,问题实际上是我如何区分在案例 1 和案例 2 中收到的术语消息,其中案例 2 应该被抑制。

You question is too business-specific and it's hard to answer directly without any plain common explanation or code on the matter.您的问题过于针对特定业务,如果没有任何简单的通用解释或代码,就很难直接回答。

Anyway you really can use an aggregator with the correlationStrategy based on that id or action fields.无论如何,您确实可以根据该idaction字段使用带有correlationStrategy的聚合correlationStrategy The releaseStrategy should be as simple as MessageCountReleaseStrategy with the threshold = 2 . releaseStrategy应该像MessageCountReleaseStrategy一样简单, threshold = 2

What to output from the aggregator you can decide in the MessageGroupProcessor implementation: you can merge both messages to a single one.您可以在MessageGroupProcessor实现中决定从聚合器输出什么:您可以将两个消息合并为一个。 You can still produce a list of them, or just ignore one of the message and produce only the another one.您仍然可以生成它们的列表,或者只是忽略其中一条消息而只生成另一条消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM