Offset commit after processing
`consume_partition(messages, handler, committer, controller)` reads one
partition and commits offsets under the at-least-once rules.
`Message` is a dataclass with `partition`, `offset` and `value`.
Rules:
- messages are processed in `offset` order;
- `handler(message)` is called exactly once per message;
- a commit happens **only after** a successful `handler`;
- the next offset is committed: `committer.commit(partition, offset + 1)`;
- if `handler` raises, that message's offset is not committed;
- on error `controller.pause(partition)` is called, processing of the partition
stops and further messages are not touched;
- a successful partition does not call `pause`.
Return a dict:
```python
{"processed": <successfully processed>,
"paused": <bool>,
"failed_offset": <offset of the failure or None>}
```
Write tests: the "handler → commit" order, an error in the middle, an error on
the first message, an empty batch and the exact committed value.
The AI mentor is available after you log in: it sees your attempt history and does not spend resources on anonymous requests.
Log in and askHint 1
What happens on a consumer restart if the offset is committed before `handler`
has actually processed the message?