Use Upstash Realtime on the server to emit events, subscribe to channels, and retrieve message history.
Emit Events#
Emit events from any server context:
Emit to specific channels:
Subscribe to Events#
Subscribe to events on a channel:
Subscribe to multiple events:
Unsubscribe#
Clean up subscriptions when done:
Retrieve History#
Fetch past messages from a channel:
History Options#
Fetch messages after this Unix timestamp (in milliseconds)
Fetch messages before this Unix timestamp (in milliseconds)
History Response#
Each history message contains:
Subscribe with History#
Replay past messages and continue subscribing to new ones:
Pass history options:
This pattern:
- Fetches messages matching the history criteria
- Replays them in chronological order
- Continues to listen for new messages
Use Cases#
Background Jobs
Stream progress updates from long-running tasks:
Event Processing
Process events with server-side logic:
Multi-Channel Broadcasting
Emit events to multiple channels:
Webhook Processing
Forward webhook events to realtime channels: