Append Sessions
Append sessions allow you to submit multiple batches of records while preserving order and managing backpressure.Basic Usage
1
Create an append session
2
Submit batches
3
Wait for acknowledgements
4
Close the session
Always call
close() to ensure all submitted batches are acknowledged before terminating the session.Backpressure Control
Append sessions implement backpressure by limiting unacknowledged bytes in flight:Advanced: Reserve and Submit
For more control in async contexts likeselect! loops, use reserve() followed by submit():
The
reserve() method is cancel-safe, making it ideal for use in select! loops.Automatic Retry
Append sessions automatically retry on transient failures:- Network disconnections
- Timeout errors
- Server unavailability
Read Sessions
Read sessions provide a streaming interface for consuming records with automatic retry and heartbeat monitoring.Basic Usage
1
Create a read session
2
Consume batches
Following the Stream
Usewith_wait_secs() to follow a stream in real-time:
Heartbeat Monitoring
Read sessions monitor for heartbeats to detect stalled connections:Error Handling
Both append and read sessions handle errors gracefully:Retryable Errors
These errors trigger automatic retry:HeartbeatTimeout(read)AckTimeout(append)ServerDisconnected(append)- Network connectivity issues
Terminal Errors
These errors terminate the session:SessionClosedSessionDropped- Permission denied
- Invalid requests
Best Practices
Sessions use
AbortOnDropHandle internally, so dropping a session will abort the background task. Always prefer explicit close() calls.