split
split<Item = Current extends Array<infer U> ? U : never>(
fn?: Splitter<Current, Item> | (exchange: Exchange<Current>) => Array<Item | SplitChild<Item>>
): RouteBuilder<Item>
Fan-out into multiple exchanges. Use .split(adapter | (exchange) => items[]) so splitters can be exchange-aware. Each returned item becomes the body of a child exchange that inherits the parent's headers and is processed independently; wrap an item in splitChild(body, headers) to give that child headers of its own.
If no splitter is provided, array bodies are split into one exchange per element; non-array bodies become a single exchange. The framework maintains routecraft.split_hierarchy headers for aggregation.
// Split array automatically
.split() // [1, 2, 3] becomes three exchanges: 1, 2, 3
// Exchange-aware: extract a nested array, one child per item
.split((exchange) => exchange.body.items)
// Split string by delimiter, with a header on each child
.split((exchange) =>
exchange.body.split(",").map((body, index) => splitChild(body, { "x-index": index }))
)
Key behaviors:
- Splitter receives the full exchange and returns an array of child bodies
- Framework overlays
routecraft.split_hierarchyand assigns new ids - Each split exchange is processed independently; aggregate to combine results. A child that fails with nothing handling it fails that aggregate