Skip to content

Consumer

Consumers read messages from topic partitions by offset through the Fetch API. RobustMQ is compatible with standard Kafka consumers: both subscription styles, offset-reset policy, long-poll fetching, and full round-tripping of key/value/headers. The group coordination flow is covered in Consumer Group.

Two Subscription Styles

StyleAPI semanticsNotes
assign(partitions)Manual partition assignmentThe client picks which partitions to read, does not join a group, no rebalance
subscribe(topics)Join a consumer groupThe coordinator assigns partitions; supports rebalance (see Consumer Group)

Starting Offset: auto.offset.reset

When a consumer has no committed offset for a partition (first-time consumption, or the offset expired), auto.offset.reset decides where to start:

ValueStart point
earliestFrom the earliest available offset
latestFrom the latest offset (only messages written afterward)

If a committed offset exists, consumption resumes from it and auto.offset.reset does not apply. Offset commit and management are covered in Offset Management.

Fetch Flow

RobustMQ Kafka fetch flow

Handling of one Fetch request:

  1. Decode — the protocol layer parses the request; Fetch v12+ identifies topics by topic_id (UUID), which the broker reverse-resolves to a topic and echoes back in the response.
  2. Read by offset — the storage layer locates data via the offset→position index and reads decoded records.
  3. Long poll — if too little data is readable, the broker waits (see below).
  4. Reframe RecordBatch — decoded records are reassembled into a Kafka RecordBatch for the response.

Long Poll

A Fetch request carries two control parameters:

ParameterMeaning
min_bytesMinimum bytes the caller wants returned
max_waitMaximum time to wait

RobustMQ's long poll is a single wait-then-reread: if the first read does not satisfy min_bytes, it waits up to max_wait and reads once more, then returns. This avoids busy-spinning when there is no new data while still responding promptly to data that arrives within max_wait.

Message Round-Trip

Each record a consumer reads keeps its full fields:

FieldNotes
keyReturned as-is
valueReturned as-is
headersReturned as-is
offsetThe continuous offset assigned by the storage layer

Compression: regardless of the producer's compression, Fetch currently always returns uncompressed batches (see Producer · Compression).

🎉 既然都登录了 GitHub,不如顺手给我们点个 Star 吧!⭐ 你的支持是我们最大的动力 🚀