Kafka Fetch API的协议规格和Wireshark抓包的对比
在Kafka中,Fetch API是用于从Broker获取消息的手段。
下面对Kafka Fetch API的协议规格(版本0)和Wireshark的抓包进行了对比分析。
参考:kafka.apache.org/protocol.ht…
Request
Fetch Request (Version: 0) => replica_id max_wait_ms min_bytes [topics]
replica_id => INT32
max_wait_ms => INT32
min_bytes => INT32
topics => topic [partitions]
topic => STRING
partitions => partition fetch_offset partition_max_bytes
partition => INT32
fetch_offset => INT64
partition_max_bytes => INT32
| FIELD | DESCRIPTION |
|---|---|
| replica_id | The broker ID of the follower, of -1 if this request is from a consumer. |
| max_wait_ms | The maximum time in milliseconds to wait for the response. |
| min_bytes | The minimum bytes to accumulate in the response. |
| topics | The topics to fetch. |
| topic | The name of the topic to fetch. |
| partitions | The partitions to fetch. |
| partition | The partition index. |
| fetch_offset | The message offset. |
| partition_max_bytes | The maximum bytes to fetch from this partition. See KIP-74 for cases where this limit may not be honored. |
Replica ID: -1:正如表格中的描述,“-1 if this request is from a consumer”Max Bytes: 32768:对应配置项fetch.message.max.bytes(默认值 32768)
// Fetch is the namespace for controlling how many bytes are retrieved by any
// given request.
Fetch struct {
...
// The default number of message bytes to fetch from the broker in each
// request (default 32768). This should be larger than the majority of
// your messages, or else the consumer will spend a lot of time
// negotiating sizes and not actually consuming. Similar to the JVM's
// `fetch.message.max.bytes`.
Default int32
Response
Fetch Response (Version: 0) => [responses]
responses => topic [partitions]
topic => STRING
partitions => partition_index error_code high_watermark records
partition_index => INT32
error_code => INT16
high_watermark => INT64
records => RECORDS
| FIELD | DESCRIPTION |
|---|---|
| responses | The response topics. |
| topic | The topic name. |
| partitions | The topic partitions. |
| partition_index | The partition index. |
| error_code | The error code, or 0 if there was no fetch error. |
| high_watermark | The current high water mark. |
| records | The record data. |
high_watermark似乎不在Response中