Subscriptions
When a new block is written to a Block table, BlockDB publishes a block subscription event through Kafka. The SDK’sSubscribe consumes that event stream, putting your downstream business logic on the chain’s “heartbeat” and closing the loop of “production → event → consumption”.
Basic usage
Subscribe to one Block table and consume block by block:listen() is a long-lived generator that yields (table_id, block) on each event. block is a Block data unit (id / height / timestamp).
Subscribing to multiple tables
When subscribing to several tables, events are distributed per table andtable_id tells you the source. Passing the same table more than once is deduplicated:
Specifying a start cursor
By default the subscription starts from the latest events. Usestart_at to start consuming from a given point in time:
start_at accepts an RFC3339 time string (for example 2026-08-17T00:00:00Z) or epoch seconds (int).
start_at can look back at most 1 hour from the current time (the server’s subscribe.max_lookback, default 1h). Anything earlier is rejected by the server with InvalidArgument.Reconnection and cursor resumption
Subscribe has built-in reconnection, so you do not need retry logic in your business code:
- Automatic reconnect: whenever the stream ends (server idle timeout, restart, rebalance, or an error), it reconnects with exponential backoff (1s → 30s).
- Cursor resumption: reconnects carry the timestamp cursor of the last event, and the server replays the events from the disconnected window.
- Replay window: the server’s replay window for old cursors is 1 hour; the SDK clamps the cursor to within 30 minutes, and cursors older than that are dropped in favor of subscribing from the latest (missed blocks are backfilled by height upstream).
for ... in listen(): — no try/except retry loop needed.
Stopping a subscription
close() can be called from another thread to stop a listen() that is blocked:
If a multi-table subscription needs height alignment (so all dependency tables are ready at the target height), use
Aligned — see Multi-table block height alignment.