Interface AggregationRepository

All Known Subinterfaces:
OptimisticLockingAggregationRepository, RecoverableAggregationRepository

public interface AggregationRepository
Persistent store for in-progress aggregated Exchange instances, used by the Aggregator EIP.

The Aggregator EIP correlates incoming exchanges by a key and accumulates them until a completion condition is satisfied. This repository is the pluggable storage layer that holds the partial aggregate between correlation events. The lifecycle for each aggregate is:

  1. get(CamelContext, String) — load the current partial aggregate (or null if none exists yet).
  2. add(CamelContext, String, Exchange) — store the updated aggregate after applying the AggregationStrategy.
  3. remove(CamelContext, String, Exchange) — delete the aggregate once the completion condition fires.
  4. confirm(CamelContext, String) — acknowledge successful downstream processing of the completed aggregate (used by persistent stores to mark records as committed).
Implementations must be thread-safe: multiple threads can aggregate concurrently for different correlation keys. The default in-memory implementation (MemoryAggregationRepository) is suitable for non-persistent use cases; persistent implementations backed by JDBC, Hazelcast, Infinispan, or file storage are available as separate Camel components.
  • Method Details

    • add

      @Nullable Exchange add(CamelContext camelContext, String key, Exchange exchange)
      Add the given Exchange under the correlation key.

      Will replace any existing exchange.

      Important: This method is not invoked if only one exchange was completed, and therefore the exchange does not need to be added to a repository, as its completed immediately.

      Parameters:
      camelContext - the current CamelContext
      key - the correlation key
      exchange - the aggregated exchange
      Returns:
      the old exchange if any existed
    • get

      @Nullable Exchange get(CamelContext camelContext, String key)
      Gets the given exchange with the correlation key

      This method is always invoked for any incoming exchange in the aggregator.

      Parameters:
      camelContext - the current CamelContext
      key - the correlation key
      Returns:
      the exchange, or null if no exchange was previously added
    • remove

      void remove(CamelContext camelContext, String key, Exchange exchange)
      Removes the exchange with the given correlation key, which should happen when an Exchange is completed

      Important: This method is not invoked if only one exchange was completed, and therefore the exchange does not need to be added to a repository, as its completed immediately.

      Parameters:
      camelContext - the current CamelContext
      key - the correlation key
      exchange - the exchange to remove
    • confirm

      void confirm(CamelContext camelContext, String exchangeId)
      Confirms the completion of the Exchange.

      This method is always invoked.

      Parameters:
      camelContext - the current CamelContext
      exchangeId - exchange id to confirm
    • getKeys

      Set<String> getKeys()
      Gets the keys currently in the repository.
      Returns:
      the keys