How to cancel reads from a subscription¶
Problem¶
You want to be able to cancel the read from a subscription so that you can take corrective action in your code and retry the read.
Solution¶
Use ControlledFragmentHandler and subscription.controlledPoll.
Discussion¶
The ControlledFragmentHandler is similar to the FragmentHandler interface, but adds a return Action:
Action onFragment(DirectBuffer buffer, int offset,
int length, Header header);
The Action that must be returned by your method informs Aeron what to do with the received fragments. Options are:
| Action | Description |
|---|---|
| ABORT | This cancels the processing of the fragment(s) in this call. The position is not advanced and the messages will be received again in the next poll |
| BREAK | Stops any additional polling, and commits the position at the end of the current fragment(s). This can be useful for finely controlling the processing of several subscriptions in a single duty cycle |
| COMMIT | Returning commit will commit the position at the current point, and allow the processing to continue. This can be useful to manage flow control |
| CONTINUE | Continues the processing in the same way the normal poll does |