Split

The Split EIP allows you to break down messages that contain multiple elements (such as lists, arrays, XML/JSON files, or multi-line texts) into smaller parts.
Each item is processed individually within a flow, making it easier to handle complex messages.

When to use Split?

  • To process each record from a JSON file separately.

  • To iterate over list elements and apply rules to each one.

  • To analyze a structured text line by line.

Parameters

Parameter Description Default value Type

Expression

Defines how the input message should be divided into smaller parts.

ExpressionDefinition

AggregationStrategy

Defines how the results of the split messages will be combined back into a single message at the end of processing.

AggregationStrategy

Aggregation Strategies

An Aggregation Strategy is the method used to merge back the results that were processed individually after the message was split.

  • Most commonly used strategy: GroupedBodyAggregationStrategy (combines the message bodies into a list).

  • Configuration in the Aggregation Strategy field : #class:org.apache.camel.processor.aggregate.GroupedBodyAggregationStrategy.

Check out each of the aggregation strategies you can use in Sensedia Integrations:

  • GroupedBodyAggregationStrategy: one of the most useful. It groups only the body of incoming messages into a java.util.List. Simple and efficient for collecting results.

  • GroupedExchangeAggregationStrategy: similar to the previous one, but instead of grouping only the bodies, it groups the complete Exchange object (with headers, properties, etc.) into a java.util.List.

  • UseLatestAggregationStrategy: discards the previously aggregated message and always keeps the latest one. Useful when only the last result matters.

  • UseOriginalAggregationStrategy: discards the new message and always keeps the original one (the first that started the aggregation). This is the default behavior of the EIP Multicast.

  • StringAggregationStrategy: a simple strategy that concatenates the bodies of messages (converted to string) into a single string, usually separated by a newline character.

Example

- from:
    uri: rest:post:/process
    steps:
      - split:
          expression:
            simple:
              expression: ${body.split(',')}
          aggregationStrategy: "#class:org.apache.camel.processor.aggregate.GroupedBodyAggregationStrategy"
      - log:
          message: "Processing order: ${body}"
  • The flow starts with a POST request sent to the /process endpoint.

  • The request body must contain a list of order IDs separated by commas, for example: 1001,1002,1003.

  • The Split EIP divides this list into individual elements, and each ID is processed separately in the log:

    • Processing order: 1001

    • Processing order: 1002

    • Processing order: 1003

  • Finally, the GroupedBodyAggregationStrategy brings all processed items back together into a single list.

Thanks for your feedback!
EDIT

Share your suggestions with us!
Click here and then [+ Submit idea]