2.9. 为分区寻求偏移
使用 位置 端点配置 Kafka Bridge consumer,以从特定的偏移检索分区的信息,然后从最新的偏移中检索分区的信息。这在 Apache Kafka 中被称为 寻求操作。
流程
为
quickstart-bridge-topic
主题的分区 0 寻求特定的偏移:curl -X POST http://localhost:8080/consumers/bridge-quickstart-consumer-group/instances/bridge-quickstart-consumer/positions \ -H 'content-type: application/vnd.kafka.v2+json' \ -d '{ "offsets": [ { "topic": "bridge-quickstart-topic", "partition": 0, "offset": 2 } ] }'
如果请求成功,则 Kafka Bridge 只返回
204
代码。将
GET
请求提交到记录
端点:curl -X GET http://localhost:8080/consumers/bridge-quickstart-consumer-group/instances/bridge-quickstart-consumer/records \ -H 'accept: application/vnd.kafka.json.v2+json'
Kafka Bridge 返回您想到的偏移信息。
通过寻找同一分区的最后偏移来恢复默认信息检索行为。此时使用 positions/end 端点。
curl -X POST http://localhost:8080/consumers/bridge-quickstart-consumer-group/instances/bridge-quickstart-consumer/positions/end \ -H 'content-type: application/vnd.kafka.v2+json' \ -d '{ "partitions": [ { "topic": "bridge-quickstart-topic", "partition": 0 } ] }'
如果请求成功,Kafka Bridge 会返回另一个
204
代码。
注意
您还可以使用 位置/更好的端点来 寻找一个或多个分区的第一个偏移量。
下一步做什么
在本快速入门中,您已使用 AMQ Streams Kafka Bridge 在 Kafka 集群上执行几个常见操作。现在 ,您可以删除之前创建的 Kafka Bridge consumer。