Kafka Fetch API的协议规格和Wireshark抓包的对比

195 阅读1分钟

Kafka Fetch API的协议规格和Wireshark抓包的对比

在Kafka中,Fetch API是用于从Broker获取消息的手段。

下面对Kafka Fetch API的协议规格(版本0)和Wireshark的抓包进行了对比分析。

image.png

参考: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
FIELDDESCRIPTION
replica_idThe broker ID of the follower, of -1 if this request is from a consumer.
max_wait_msThe maximum time in milliseconds to wait for the response.
min_bytesThe minimum bytes to accumulate in the response.
topicsThe topics to fetch.
topicThe name of the topic to fetch.
partitionsThe partitions to fetch.
partitionThe partition index.
fetch_offsetThe message offset.
partition_max_bytesThe maximum bytes to fetch from this partition. See KIP-74 for cases where this limit may not be honored.

image.png

  • 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
FIELDDESCRIPTION
responsesThe response topics.
topicThe topic name.
partitionsThe topic partitions.
partition_indexThe partition index.
error_codeThe error code, or 0 if there was no fetch error.
high_watermarkThe current high water mark.
recordsThe record data.

image.png

  • high_watermark似乎不在Response中