MQ Broker Interaction
This document catalogs the Redis commands actually used by the mq/ module, with sequence diagrams and Kafka semantic mappings, to aid understanding and troubleshooting. The command list has been verified against mq/src/main/java; implementation goes through Redisson APIs (RStream/RScript/RBucket etc.), and the tables below show the corresponding raw commands.
Key conventions: control key prefix keyPrefix (default streaming:mq), data stream prefix streamKeyPrefix (default stream:topic), see partition/StreamKeys.
Core Commands
Produce
XADD stream:topic:{t}:p:{i} [MAXLEN = N] * field value …: write message to partition stream; returnstimestamp-seqmessageId. WhenretentionMaxLenPerPartition > 0, Lua atomically executesXADD ... MAXLEN = N(=exact trim, Redis 7+; older versions fall back toXADD+XTRIM+ pagedXDELsafety net).
Consumer Group
XGROUP CREATE <stream> <group> 0-0 MKSTREAM: create consumer group (subscribeandDefaultBroker.readGroupboth checkXINFO GROUPSvia Lua first, swallowBUSYGROUP). Group created at0-0, so backlog before group creation is also delivered.XREADGROUP GROUP <group> <consumer> COUNT n BLOCK ms STREAMS <stream> >: read undelivered entries within group (RedissonStreamReadGroupArgs.neverDelivered()).XACK <stream> <group> <id …>: acknowledge processing complete, remove from PEL.XPENDING <stream> <group> <start> <end> <count>(RedissonlistPending): query unacked entries (idle, delivery count).XCLAIM <stream> <group> <consumer> <min-idle-time> <id>(Redissonclaim): claim pending entries idle >claimIdleMs. Implementation useslistPending + claimcombo; does not useXAUTOCLAIM.
ACK Delete Policy (MqOptions.ackDeletePolicy, default none)
immediate:XACKthenXDEL(safe only for single-group consumption).all-groups-ack:SADD streaming:mq:acks:{t}:p:{i}:{id} <group>(TTLacksetTtlSec); when set size ≥XINFO GROUPSregistered group count,XDELand delete set.
Commit Frontier
EVAL <lua>: after ACK, atomically maintainsstreaming:mq:commit:{t}:p:{i}(Hash, field=group) — onlyHSETwhen new id (ms-seq compare) exceeds stored value.
Failure Recovery & Rebalance
SET streaming:mq:lease:{t}:{g}:{i} <consumerId> NX EX <ttl>: acquire partition lease.EVAL <lua>: renew (compare owner id thenPEXPIRE) and release (compare owner id thenDEL), prevents deleting successor's lease.
Delayed Retry
ZADD streaming:mq:retry:{t} <dueAtMs> <itemKey>: entry enters retry bucket by due time (sorted set).HSET streaming:mq:retry:item:{t}:{uuid} topic ... partitionId ... payload ... key ... headers ... retryCount ... maxRetries ... originalMessageId ...: multi-field string envelope;payload/headersJSON-encoded; null payload omitspayloadfield.- Distributed lock
streaming:mq:retry:lock:{t}(RedissonRLock, waitretryLockWaitMs, leaseretryLockLeaseMs): serializes mover per Topic. Note this key is a literal constant, does not vary withkeyPrefix. EVAL <lua>: atomically executes "ZRANGEBYSCORE take due (≤retryMoverBatch) → XADD back to partition → ZREM → DEL Hash".
Dead Letter Queue (DLQ)
XADD stream:topic:{t}:dlq * ...: dead letter fields includeoriginalTopic / partitionId / originalMessageId / retryCount / maxRetries / timestamp / failedAt / headers / payload.- Replay:
XRANGE <dlq> <id> <id>reads entries, thenXADD stream:topic:{t}:p:{pid}back to original partition bypartitionId; replay does not auto-XDELDLQ entries.
Topic Governance
XINFO STREAM / XINFO GROUPS: query stream info (length, last id, group count) and group stats (consumer count, pending, last-delivered-id).XTRIM MAXLEN = N/XTRIM MAXLEN ~ N/XTRIM MINID <id>: trim by length or time. Write path uses exactMAXLEN =; periodicMAXLEN ~/MINID ~run by spring-boot-starter'sStreamRetentionHousekeeperpertrimIntervalSec.DEL <key …>:deleteTopicremoves partition streams, DLQ, meta, partition set, and Topic's payload keys (caution: data loss).
Large Payload (> 64KB, PayloadHeaders.MAX_INLINE_PAYLOAD_SIZE)
SET streaming:mq:payload:{t}:p:{i}:{uuid} <json>: stream only keeps headerx-payload-hash-refreference.- ACK triggers
DELof that key (primary deletion path); indexstreaming:mq:payload:idx:{t}(Set) andstreaming:mq:payload:ts(ZSET) provide fallback cleanup.
Produce Sequence
Consume / Retry / Dead Letter
Lease & Reclaim
Kafka Mapping Table
- Produce → Partition:
XADD≈ Kafka produce to partition - Consume Group & Commit:
XREADGROUP/XACK≈ fetch/commit - Pending & Offset:
XPENDING≈ in-flight (Kafka side infers from lag/offset) - Rebalance & Reclaim: Lease +
XPENDING+XCLAIM≈ Group coordinator / rebalance - Delayed Retry:
ZADD+Hash + Lua mover ≈ Retry topic / delayed replay - Dead Letter:
stream:topic:{t}:dlq≈ DLQ topic - Retention:
XADD ... MAXLEN =/XTRIM≈ retention
Notes
- Redisson APIs wrap
XINFO/XPENDING/XCLAIM/...raw commands; this doc lists raw commands for Kafka semantic cross-reference. - Orphan reclaim uses
listPending + claim(XCLAIM), notXAUTOCLAIM, so it works on older Redis versions lackingXAUTOCLAIM.
Version: 0.2.0 Last Updated: 2026-10-05