Routing

Pipelite supports three routing types, accessible via the .toRoute() method of the DSL.

Content-Based Router

The Content-Based Router routes the message to one of the flows listed in the routing table based on content.

.toRoute(route -> route.contentBased()               (1)
    .when(new PayloadTypeCondition(OrderEvent.class), (2)
          "link://order-processing-flow")
    .when(new ExpressionCondition("${header.type} == 'PAYMENT'"),
          "link://payment-flow")
    .otherwise("link://default-flow")                        (3)
    .build()
)
1 Selects content-based mode.
2 Each .when(condition, flowName) adds an entry to the routing table.
3 .otherwise defines the fallback flow if no condition is satisfied.
A destination is a URL: link://<source endpoint name> reaches an internal flow (the name its fromSource(…​) declares), any other channel adapter protocol reaches an external system. A bare name is rejected when the flow is defined.

Available conditions

Class Description

PayloadTypeCondition

Checks that the payload is an instance of the specified type.

ExpressionCondition

Evaluates a textual expression (see Expressions).

To create custom conditions, implement the Condition interface:

public interface Condition {
    boolean evaluate(Exchange exchange);
}

Recipient List

The Recipient List pattern sends the message to multiple flows simultaneously.

.toRoute(route -> route.dynamic()
    .toRecipientList(list -> {
        list.addRecipient("flow-a");
        list.addRecipient("flow-b");
        return list;
    })
)
The toRecipientList API via ProcessOperations is deprecated. Prefer the variant via toRoute(route → route.dynamic()).