Consumer retries and dead-letter
`process_batch(messages, handler, max_retries=2)` consumes a batch of messages.
`Message` is a dataclass with `offset` and `value`. `handler(message)` can:
- succeed;
- raise `KafkaError` — a transient error, the message can be retried;
- raise `ValueError` — a poison pill, retrying is pointless.
Rules:
- a successful message appears in `acked` exactly once;
- `KafkaError` is retried, at most `max_retries + 1` attempts in total;
- when attempts run out, the message goes to `dead`;
- `ValueError` goes to `dead` immediately, with no retries;
- the order of messages in `acked` and `dead` is preserved;
- an empty batch gives two empty lists.
Write tests with a handler function: success, a transient error with a retry,
exhausted attempts, a poison pill, `max_retries=0` and an empty batch.
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
Which error type means "retry", and which means "this message cannot be saved"?