webpatser/resonate-delivery v1.2.0. Every broadcast is logged to a per-channel Redis Stream. A reconnecting client sends the id of the last message it saw, and the plugin replays everything since before live delivery resumes. It addresses the case "I dropped for 20 seconds and missed messages."
What you get
- A Laravel broadcaster, the
resonate-deliverydriver, that wraps Reverb, logs every broadcast and tags the payload with a monotonic_replay_id. - A Resonate server plugin that, when a subscribe carries
last_event_id, replays the missed messages aftersubscription_succeededand before any live broadcast. - Bounded retention on two axes:
MAXLEN ~ Ncaps how long each stream gets, and a refreshed TTL caps how long an idle stream key survives.
What it is and is not
- At-least-once within retention. With the default cap of 1000 messages per channel, a client that drops for 5 minutes on a low-traffic channel reconnects seamlessly. A client offline for hours on a high-traffic channel sees a clean break.
- Ordered. Everything replayed reaches the client before any live broadcast on that channel.
- Duplicates at the seam. A message published as a client subscribes may arrive in the replay and live. Both copies carry the same
_replay_id, so the client deduplicates on it. - Best-effort logging. If the delivery Redis is unreachable, the broadcast still goes out live. It is not logged and carries no
_replay_id. - Bounded replays. One replay sends at most
replay_max_messagesmessages. Each connection may start at mostreplay_budget_replaysreplays and receivereplay_budget_messagesreplayed messages perreplay_budget_windowseconds. When a replay is cut short the client receives no signal. - Encrypted channels are live-only.
private-encrypted-*channels are never logged or replayed. - No ACK protocol. This is not a message queue.
- Server broadcasts only.
client-*whispers are not logged.
Install
composer require webpatser/resonate-deliveryphp artisan vendor:publish --tag=resonate-delivery-config
Add the wrapping driver to config/broadcasting.php and point your default at it:
'default' => env('BROADCAST_DRIVER', 'resonate-delivery'),'connections' => [ // ... keep your existing 'reverb' connection as-is 'resonate-delivery' => [ 'driver' => 'resonate-delivery', 'underlying' => 'reverb', ],],
The wrapper delegates auth and the WebSocket send to the underlying connection, so your Reverb setup is unchanged.
Register the server plugin in config/reverb.php:
'plugins' => [ \Webpatser\ResonateDelivery\MessageReplayPlugin::class,],
Restart Resonate. Requirements: PHP 8.6+, Laravel 13, Resonate 1.4+ and Redis 5+ (Redis Streams).
Client protocol
A client that wants replay sends last_event_id in the subscribe payload:
{"event": "pusher:subscribe", "data": {"channel": "presence-chat.42", "auth": "...", "last_event_id": "1700000000000-0"}}
The client reads data._replay_id on every message it receives and remembers the highest. On reconnect it sends that value. First-time subscribers omit the field and get no replay. Laravel Echo and the JS Pusher client have no built-in support for this field, so subscribe with the custom data field through their lower-level subscription APIs.
Ordering
The plugin only remembers the cursor on pusher:subscribe, so nothing touches Redis before core has authorized the subscribe. Resonate then joins the connection, sends subscription_succeeded and calls every plugin's onSubscribe. This plugin reads the missed window there. From the join until the last onSubscribe returns, Resonate holds every live frame for that connection and delivers them afterwards in arrival order. A connection already subscribed to the channel gets no replay.
Retention
MAXLEN ~ N bounds one stream and says nothing about how many streams exist. A per-entity channel scheme such as private-orders.{id} mints a stream key per entity. Every append therefore also stamps retention.ttl on the key (default 7 days). An active channel never expires, and a quiet one is reclaimed a window later. Set ttl to 0 to keep every stream forever. Pick a window longer than the longest disconnect you intend to support.
Configuration
| Key | Default | Purpose |
|---|---|---|
connection |
REDIS_* env |
Redis server hosting the streams. The broadcaster and the plugin must point at the same server and database. Per-plugin overrides use RESONATE_DELIVERY_REDIS_*. |
key_prefix |
delivery |
Namespace for stream keys, {prefix}:{appId}:{channel}. Env: RESONATE_DELIVERY_PREFIX. |
retention.default_max_messages |
1000 |
Default per-channel cap. Env: RESONATE_DELIVERY_RETENTION. |
retention.per_channel |
[] |
fnmatch glob to max-messages overrides. |
retention.ttl |
604800 |
Seconds a stream key survives its last append. 0 never expires. Env: RESONATE_DELIVERY_TTL. |
replay_id_field |
_replay_id |
The data key that carries each message's stream id. Env: RESONATE_DELIVERY_ID_FIELD. |
underlying |
reverb |
Name of the broadcaster the wrapper delegates to. Env: RESONATE_DELIVERY_UNDERLYING. |
replay_batch_size |
100 |
XRANGE page size during replay. Env: RESONATE_DELIVERY_BATCH_SIZE. |
replay_max_messages |
10000 |
Most messages one replay sends. 0 removes the cap. Env: RESONATE_DELIVERY_MAX_REPLAY. |
replay_max_pending |
100 |
Most last_event_id cursors one connection holds for unconfirmed subscribes. Env: RESONATE_DELIVERY_MAX_PENDING. |
replay_budget_window |
60 |
Length in seconds of one per-connection replay budget window, at least 1. Env: RESONATE_DELIVERY_BUDGET_WINDOW. |
replay_budget_replays |
100 |
Most replays one connection may start per window. 0 removes the cap. Env: RESONATE_DELIVERY_BUDGET_REPLAYS. |
replay_budget_messages |
10000 |
Most replayed messages one connection may receive per window. 0 removes the cap. Env: RESONATE_DELIVERY_BUDGET_MESSAGES. |