Stats and Monitoring¶
MessageBus tracks per-channel counters automatically via a shared Stats instance.
Available Counters¶
For each channel named :orders, the following counters are tracked:
| Counter | Description |
|---|---|
:orders_published |
Messages published |
:orders_delivered |
All subscribers ACKed (message fully delivered) |
:orders_nacked |
Explicit nacks by subscribers |
:orders_timed_out |
Delivery timeouts (auto-nack) |
:orders_dead_lettered |
Entries added to the DLQ |
:orders_throttled |
Publishes that were rate-limited |
Reading Stats¶
bus.stats[:orders_published] # => 42
bus.stats[:orders_delivered] # => 40
bus.stats[:orders_dead_lettered] # => 2
Snapshot¶
Get all counters as a Hash:
Reset¶
Zero all counters:
Or reset everything (channels + stats):
Using Stats Directly¶
When using Channel without a MessageBus, pass a Stats instance:
stats = TypedBus::Stats.new
channel = TypedBus::Channel.new(:work, stats: stats, timeout: 5)
# ... publish and subscribe ...
stats[:work_published] # => N
Monitoring Pattern¶
Combine stats with DLQ callbacks for real-time alerting: