Message and Headers

Message

The Message (package io.pipelite.spi.flow.exchange) is the container for the application payload. Each Exchange has an input Message and, optionally, an output Message.

Main API

Message input = exchange.getInput();

// Payload access
Object payload       = input.getPayloadAs(Object.class);
MyDto dto            = input.getPayloadAs(MyDto.class);
Class<?> payloadType = input.getPayloadType();
boolean hasPayload   = input.hasPayload();

// Payload modification (inside a processor)
input.setPayload(newValue);

SimpleMessage

The concrete implementation is SimpleMessage, which carries a typed payload and a map of message-own headers. Default values are created by the MessageFactory (injected by the context).

Headers

The Headers class (interface and implementation HeadersImpl) provides access to message metadata.

Read

Headers headers = exchange.getHeaders();

// Optional read
Optional<String> value = headers.tryGetHeader("x-request-id");

// Read with expectation (throws NoSuchElementException if absent)
String value = headers.expectHeader("x-request-id");

// Typed read
Optional<Integer> n = headers.tryGetHeaderAs("retry-count", Integer.class);

// Presence check
boolean present = headers.hasHeader("x-request-id");

Write

headers.putHeader("x-correlation-id", "xyz-789");
headers.removeHeader("x-temp");

System headers

The framework uses several reserved headers, defined in IOKeys:

Constant Purpose

IOKeys.RETURN_ADDRESS_HEADER_NAME

Address of the reply flow (Return Address pattern)

IOKeys.ROUTING_SLIP_PROPERTY_NAME

Dynamic list of flows to traverse (property, not header)

Do not use system-reserved keys as application headers to avoid collisions with framework behaviour.