如何在 kafka 中使用来自主题特定分区的消息

问题描述

我想让 kafka 消费者消费来自主题特定/指定分区的消息

它使用 kafka-console-consumer.sh 和开关 --partition partition_number

我正在使用来自 librdkafka

kafka_complex_consumer_example.c 代码

根据静态代码分析,我觉得它可以达到我的目的,但我无法找出要传递给 main(int argc & char **argv) 函数的确切命令行参数,以便代码运行和启动在主题的特定分区上消费。

Have a look at the code here - rdkafka_complex_consumer_example.c

Full github code of librdkafka here FYR

如果此代码不能用于此目的,请指定一些其他可以帮助的代码

解决方法

如果您查看用法字符串,在主题名称后面放一个冒号表示要从哪个分区使用

更具体地说,topicpartition 类型保存特定分区的信息,这一行创建了这些信息的列表

https://github.com/edenhill/librdkafka/blob/master/examples/rdkafka_complex_consumer_example.c#L528