Interface Step<I,O>
- Type Parameters:
I- payload this step receivesO- payload it produces for the next step
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
class EnrichOrder implements Step<Order, Enriched> {
public Enriched handle(Message<Order> message) {
Order order = message.payload();
return new Enriched(order, customers.lookup(order.customerId()));
}
}
Returning the next payload rather than publishing it keeps a step testable — it is a
function, and a test calls it — and lets the builder thread types along the chain, so a step
that produces an Enriched cannot be put where one producing an Order belongs.
Returning null ends the route for that message. A step that filters
is a step that sometimes returns nothing; the message is acknowledged and nothing downstream
ever sees it. That is a decision, not a failure, and it is counted separately from both.
A step should be idempotent. Every hop is at-least-once, so a step sees the same message twice whenever a publish succeeds and its acknowledgement does not — configure an idempotency store on the ones where repeating the work would matter.
-
Method Summary
-
Method Details
-
handle
- Parameters:
message- the message to handle- Returns:
- the payload for the next step, or
nullto end the route here - Throws:
Exception- to fail this step, applying whatever failure policy it was configured with
-