简体   繁体   English

如何在融合的 kafka 休息代理中访问主题的最新偏移量以计算滞后

[英]how to access latest offset of topic in confluent kafka rest proxy to calculate lag

在融合的 kafka 休息代理中,我们可以获得特定消费者组的最后提交的偏移量,但是我们如何获得主题的最新偏移量来计算滞后。

You can use Kafka REST Proxy to fetch the latest offset committed for a particular partition .您可以使用 Kafka REST 代理来获取为特定分区提交的最新偏移量。 According to the Confluent Docs ,根据Confluent Docs

 GET /consumers/(string: group_name)/instances/(string: instance)/offsets

Get the last committed offsets for the given partitions (whether the commit happened by this process or another).获取给定分区的最后提交的偏移量(提交是由这个进程还是其他进程发生的)。

Note that this request must be made to the specific REST proxy instance holding the consumer instance.请注意,必须向持有消费者实例的特定 REST 代理实例发出此请求。

Parameters:参数:

  • group_name (string) -- The name of the consumer group group_name (string) -- 消费者组的名称

  • instance (string) -- The ID of the consumer instance Request JSON instance (string) -- 消费者实例的 ID 请求 JSON

Array of Objects:对象数组:

  • partitions -- A list of partitions to find the last committed offsets for partitions -- 一个分区列表,用于查找最后提交的偏移量
  • partitions[i].topic (string) -- Name of the topic partitions[i].topic (string) -- 主题名称
  • partitions[i].partition (int) -- Partition ID partitions[i].partition (int) -- 分区 ID

Response JSON Array of Objects:对象的响应 JSON 数组:

  • offsets -- A list of committed offsets offsets -- 提交的偏移量列表
  • offsets[i].topic (string) -- Name of the topic for which an offset was committed offsets[i].topic (string) -- 提交偏移量的主题名称
  • offsets[i].partition (int) -- Partition ID for which an offset was committed offsets[i].partition (int) -- 提交偏移量的分区 ID
  • offsets[i].offset (int) -- Committed offset offsets[i].offset (int) -- 提交的偏移量
  • offsets[i].metadata (string) -- Metadata for the committed offset offsets[i].metadata (string) -- 提交偏移量的元数据

Status Codes:状态代码:

  • 404 Not Found -- 404未找到-
  • Error code 40402 -- Partition not found错误代码 40402 -- 未找到分区
  • Error code 40403 -- Consumer instance not found错误代码 40403 -- 未找到消费者实例

Example Request:示例请求:

GET /consumers/testgroup/instances/my_consumer/offsets HTTP/1.1
Host: proxy-instance.kafkaproxy.example.com
Accept: application/vnd.kafka.v2+json, application/vnd.kafka+json, application/json

{
  "partitions": [
    {
      "topic": "test",
      "partition": 0
    },
    {
      "topic": "test",
      "partition": 1
    }

  ]
}

Example Response:示例响应:

HTTP/1.1 200 OK
Content-Type: application/vnd.kafka.v2+json

{"offsets":
 [
  {
    "topic": "test",
    "partition": 0,
    "offset": 21,
    "metadata":""
  },
  {
    "topic": "test",
    "partition": 1,
    "offset": 31,
    "metadata":""
  }
 ]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM