You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
GH-9754: Add discardIndividuallyOnExpiry to aggregator
Fixes: #9754
Right now a correlation handler can discard messages in the expired group one by one.
In some scenarios it would be useful to have single message in discard for the whole group.
* Expose `discardIndividuallyOnExpiry` for the `AbstractCorrelatingMessageHandler`,
and `AggregatorFactoryBean`, and respective `CorrelationHandlerSpec` for DSL.
This new option takes action only if a `discardChannel` is provided,
and `sendPartialResultOnExpiry` is not set to `true`.
When `discardIndividuallyOnExpiry` is false, the messages in the expired group are packed
into a list for payload of a discarding single message.
* Test and document the new feature
Copy file name to clipboardExpand all lines: spring-integration-core/src/main/java/org/springframework/integration/aggregator/AbstractCorrelatingMessageHandler.java
Copy file name to clipboardExpand all lines: spring-integration-core/src/test/java/org/springframework/integration/aggregator/AbstractCorrelatingMessageHandlerTests.java
Copy file name to clipboardExpand all lines: src/reference/antora/modules/ROOT/pages/aggregator.adoc
+8-4
Original file line number
Diff line number
Diff line change
@@ -213,6 +213,10 @@ Any new messages for this group are sent to the discard channel (if defined).
213
213
Setting `expire-groups-upon-completion` to `true` (the default is `false`) removes the entire group, and any new messages (with the same correlation ID as the removed group) form a new group.
214
214
You can release partial sequences by using a `MessageGroupStoreReaper` together with `send-partial-result-on-expiry` being set to `true`.
215
215
216
+
Starting with version 6.5, the correlation handler can also be configured with a `discardIndividuallyOnExpiry` option to discard the whole group as a single message.
217
+
Essentially, the payload of this message is a list of messages from the expired group.
218
+
Works only if `sendPartialResultOnExpiry` is set to `false` (default) and `dicardChannel` is provided.
219
+
216
220
IMPORTANT: To facilitate discarding of late-arriving messages, the aggregator must maintain state about the group after it has been released.
217
221
This can eventually cause out-of-memory conditions.
218
222
To avoid such situations, you should consider configuring a `MessageGroupStoreReaper` to remove the group metadata.
@@ -519,7 +523,7 @@ Empty groups can be removed later by using a `MessageGroupStoreReaper` in combin
519
523
`expire-groups-upon-completion` relates to "`normal`" completion when the `ReleaseStrategy` releases the group.
520
524
This defaults to `false`.
521
525
522
-
If a group is not completed normally but is released or discarded because of a timeout, the group is normally expired.
526
+
If a group is not complete normally but is released or discarded because of a timeout, the group is normally expired.
523
527
Since version 4.1, you can control this behavior by using `expire-groups-upon-timeout`.
524
528
It defaults to `true` for backwards compatibility.
525
529
@@ -531,12 +535,12 @@ Timed-out groups are either discarded or a partial release occurs (based on `sen
531
535
Since version 5.0, empty groups are also scheduled for removal after `empty-group-min-timeout`.
532
536
If `expireGroupsUponCompletion == false` and `minimumTimeoutForEmptyGroups > 0`, the task to remove the group is scheduled when normal or partial sequences release happens.
533
537
534
-
Starting with version 5.4, the aggregator (and resequencer) can be configured to expire orphaned groups (groups in a persistent message store that might not otherwise be released).
538
+
Starting with version 5.4, the aggregator (and resequencer) can be configured to expire orphaned groups (those in a persistent message store that might not otherwise be released).
535
539
The `expireTimeout` (if greater than `0`) indicates that groups older than this value in the store should be purged.
536
540
The `purgeOrphanedGroups()` method is called on start up and, together with the provided `expireDuration`, periodically within a scheduled task.
537
541
This method is also can be called externally at any time.
538
542
The expiration logic is fully delegated to the `forceComplete(MessageGroup)` functionality according to the provided expiration options mentioned above.
539
-
Such a periodic purge functionality is useful when a message store is needed to be cleaned up from those old groups which are not going to be released any more with regular message arrival logic.
543
+
Such a periodic purge functionality is useful when a message store is needed to be cleaned up from those old groups which are not going to be released anymore with regular message arrival logic.
540
544
In most cases this happens after an application restart, when using a persistent message group store.
541
545
The functionality is similar to the `MessageGroupStoreReaper` with a scheduled task, but provides a convenient way to deal with old groups within specific components, when using group timeout instead of a reaper.
542
546
The `MessageGroupStore` must be provided exclusively for the current correlation endpoint.
@@ -695,7 +699,7 @@ Otherwise, it is discarded.
695
699
There is a difference between `groupTimeout` behavior and `MessageGroupStoreReaper` (see xref:aggregator.adoc#aggregator-xml[Configuring an Aggregator with XML]).
696
700
The reaper initiates forced completion for all `MessageGroup` s in the `MessageGroupStore` periodically.
697
701
The `groupTimeout` does it for each `MessageGroup` individually if a new message does not arrive during the `groupTimeout`.
698
-
Also, the reaper can be used to remove empty groups (empty groups are retained in order to discard late messages if `expire-groups-upon-completion` is false).
702
+
Also, the reaper can be used to remove empty groups (those retained in order to discard late messages if `expire-groups-upon-completion` is false).
699
703
700
704
Starting with version 5.5, the `groupTimeoutExpression` can be evaluated to a `java.util.Date` instance.
701
705
This can be useful in cases like determining a scheduled task moment based on the group creation time (`MessageGroup.getTimestamp()`) instead of a current message arrival as it is calculated when `groupTimeoutExpression` is evaluated to `long`:
0 commit comments