Skip to content

How to read fragmented messages

Problem

Your subscription is receiving data from a publication that offers messages larger than maxPayloadLength, and you want to receive whole messages, not fragments.

Solution

Use a FragmentAssembler in your subscription.

Sample

Use a FragmentAssembler that wraps your FragementHandler:

1
2
3
4
FragmentHandler handler = new MyCustomFragmentHandler();
FragmentAssembler assembler = new FragmentAssembler(handler);
...
final int fragementsReceived = subscription.poll(assember, 10);

Discussion

Aeron automatically fragments outbound messages, but does not automatically reconstruct fragmented messages on the receive path. Using a FragmentAssembler results in a buffer copy when reading fragmented messages.

See Also