Redis Reliable Pub/Sub
The RedissonPubSubReliableEventStore provides a distributed, replay-capable event store for socketio4j using Redis Reliable Topics backed by Redis Streams. It supports multi-node synchronization with optional stream trimming to control memory footprint, enabling durability across server restarts while still delivering events in near real time.
Redis Reliable Pub/Sub uses Streams internally for durability, but does not expose offsets; Redis Streams exposes offsets directly, enabling controlled replay and connection-state recovery feature(planned for development).
Key characteristics
Reliable delivery via Redis Streams — retains recent messages for controlled replay
Stream-backed topics —
RReliableTopicensures messages are persisted and delivered to late subscribersOptional auto-trimming — prevents unbounded stream growth using scheduled
XTRIMAsynchronous dispatch — delivery callbacks occur outside Netty event loops
Duplicate prevention — filters self-originated events via
nodeId
How it works
publish0writes events to a reliable topic, which internally appends to a Redis streamsubscribe0registers a listener on the reliable topic; events are pulled from the underlying stream even after reconnectStream entries are periodically trimmed based on
streamMaxLengthandtrimEveryTrimming is performed asynchronously in a daemon thread to avoid blocking I/O
Stream metadata (
activePubTopics,activeSubTopics,trimTopics) is tracked per event type
Modes
MULTI_CHANNEL
Per-event-type streams + reliable topics
Default; isolates traffic and maintains ordering per event type
SINGLE_CHANNEL
All events routed to a single reliable stream
When strict global ordering is required
Advantages
👍 Messages persisted in Redis stream — recoverable up to trim limits 👍 Suitable for multi-node synchronization with durability 👍 Optional trimming prevents unbounded memory use 👍 Can replay recent messages after reconnects (within trimmed range) 👍 Familiar Redis deployment model, no Kafka/NATS needed
Limitations
ℹ️ Not fully exactly-once — duplicates may occur after restart or reconnections ℹ️ Ordering is per-stream — cross-event ordering requires single-channel mode ℹ️ Requires Redis Streams support (Redis 5+) ℹ️ Reliability depends on stream retention configuration and trimming strategy
Delivery guarantee: At-least-once semantics — listeners must be idempotent to handle potential duplicate deliveries.
Last updated
Was this helpful?