C++ librdkafka:rd_-kafka_分配返回分配分区的偏移量-1001

C++ librdkafka:rd_-kafka_分配返回分配分区的偏移量-1001,c++,apache-kafka,librdkafka,C++,Apache Kafka,Librdkafka,当我向消费者查询分配的主题分区列表时,结果中的所有分区的偏移量都是-1001。 如果我打印出收到消息的偏移量,则偏移量设置为正确的值 这是我用来使用消息的代码: > %4|1580198390.566|CONFWARN|rdkafka#consumer-1| [thrd:app]: Configuration property offset.store.method is deprecated: Offset commit store method: 'file' - DEPRECATED

当我向消费者查询分配的主题分区列表时,结果中的所有分区的偏移量都是-1001。 如果我打印出收到消息的偏移量,则偏移量设置为正确的值

这是我用来使用消息的代码:

> %4|1580198390.566|CONFWARN|rdkafka#consumer-1| [thrd:app]: Configuration property offset.store.method is deprecated: Offset commit store method: 'file' - DEPRECATED: local file store (offset.store.path, et.al), 'broker' - broker commit store (requires Apache Kafka 0.8.2 or later on the broker).

> % Subscribed to 1 topic(s), waiting for rebalance and messages...

> % Consumer group rebalanced: assigned:
> NewTestingTopic [0] offset -1001, NewTestingTopic [1] offset -1001, 
> NewTestingTopic [2] offset -1001, NewTestingTopic [3] offset -1001
> NewTestingTopic [0] offset -1001, NewTestingTopic [1] offset -1001, 
> NewTestingTopic [2] offset -1001, NewTestingTopic [3] offset -1001
> 
> Message on NewTestingTopic [0] at offset 25:
> Key: 0
> Value: ExampleMessage 0
> 
> NewTestingTopic [0] offset -1001, NewTestingTopic [1] offset -1001, 
> NewTestingTopic [2] offset -1001, NewTestingTopic [3] offset -1001
> 
> Message on NewTestingTopic [3] at offset 41:
> Key: 1
> Value: ExampleMessage 1
静态无效打印分区列表(文件*fp,
康斯特路卡夫卡主题分区列表
*分区){
int i;
对于(i=0;icnt;i++){
fprintf(fp,“%s%s[%d]偏移量%lld”,
i>0?,“:”,
分区->元素[i]。主题,
分区->元素[i]。分区,
分区->元素[i].偏移量);
}
fprintf(fp,“\n”);
}
静态无效重新平衡(rd_kafka_t*rk、rd_kafka_resp_err_t err、rd_kafka_topic_partition_list_t*partitions、void*不透明){
fprintf(标准偏差,“%消费者群体重新平衡:”);
开关(错误){
案例RD_KAFKA_RESP_ERR__分配_分区:
fprintf(标准,“已分配:\n”);
打印分区列表(标准、分区);
rd_kafka_分配(rk,分区);
打破
案例RD_KAFKA_RESP_ERR__撤销_分区:
fprintf(标准,“撤销:\n”);
打印分区列表(标准、分区);
rd_kafka_赋值(rk,空);
打破
违约:
fprintf(标准,“失败:%s\n”,rd_kafka_err2str(err));
rd_kafka_赋值(rk,空);
打破
}
}
int main()
{
卡夫卡学院;
卡夫卡形态;
卡夫卡的错误;
charerrstr[512];
const char*brokers{“localhost:9092”};
const char*groupid{“OffsetTest”};
常量字符*主题[]={“偏移测试”};
卡夫卡主题分区列表订阅;
conf=rd_kafka_conf_new();
if(rd_kafka_conf_set(conf,“bootstrap.servers”),代理,
errstr,sizeof(errstr))!=RD\u KAFKA\u CONF\u OK){
fprintf(strderr,“%s\n”,errstr);
卡夫卡形态毁灭;
返回1;
}
如果(rd_kafka_conf_set)(conf,“group.id”,groupid,
errstr,sizeof(errstr))!=RD\u KAFKA\u CONF\u OK){
fprintf(strderr,“%s\n”,errstr);
卡夫卡形态毁灭;
返回1;
}
if(rd_kafka_conf_)set(conf,“enable.auto.commit”,“false”,
errstr,sizeof(errstr))!=RD\u KAFKA\u CONF\u OK){
fprintf(strderr,“%s\n”,errstr);
卡夫卡形态毁灭;
返回1;
}
if(rd_kafka_conf_set)(conf,“auto.offset.reset”,“最早”,
errstr,sizeof(errstr))!=RD\u KAFKA\u CONF\u OK){
fprintf(strderr,“%s\n”,errstr);
卡夫卡形态毁灭;
返回1;
}
if(rd_kafka_conf_set)(conf,“offset.store.method”,“broker”,
errstr,sizeof(errstr))!=RD\u KAFKA\u CONF\u OK){
fprintf(strderr,“%s\n”,errstr);
卡夫卡形态毁灭;
返回1;
}
rd_kafka_conf_set_rebalance_cb(conf,rebalance_cb);
rk=rd_kafka_new(rd_kafka_CONSUMER,conf,errstr,sizeof(errstr));
如果(!rk){
fprintf(stderr,“%%未能创建新的使用者:%s\n”,errstr);
返回1;
}
conf=NULL;
卡夫卡民意测验(rk);
订阅=rd_kafka_topic_partition_list_new(1);
rd_kafka_主题_分区_列表_添加(订阅,主题[0],rd_kafka_分区_UA);
err=rd_kafka_subscribe(rk,subscribe);
如果(错误){
fprintf(标准,
“%%未能订阅%d个主题:%s\n”,
订阅->cnt,rd_kafka_err2str(err));
卡夫卡主题分区列表销毁(订阅);
卡夫卡(rk);
返回1;
}
fprintf(标准,
%%订阅了%d个主题
“正在等待重新平衡和消息…\n”,
订阅->cnt);
卡夫卡主题分区列表销毁(订阅);
int runningCounter=0;
while(运行计数器!=10){
卡夫卡消息;
rkm=卡夫卡消费者调查(rk,100);
if(!rkm){
睡眠(2000年);
运行计数器++;
继续;
}
如果(rkm->err){
fprintf(标准,
“%%使用者错误:%s\n”,
卡夫卡消息(rkm);
卡夫卡消息销毁(rkm);
继续;
}
rd_kafka_topic_partition_list_t*list;
err=rd_kafka_分配(rk和列表);
如果(错误){
fprintf(标准,
“%%未能订阅%d个主题:%s\n”,
订阅->cnt,rd_kafka_err2str(err));
卡夫卡主题分区列表销毁(订阅);
返回1;
}
打印分区列表(标准,列表);
卡夫卡主题、分区、列表、销毁(列表);
printf(“偏移量%lld:\n处%s[%d]上的邮件”,
rd_kafka_主题_名称(rkm->rkt),rkm->partition,
rkm->偏移量);
如果(rkm->键)
printf(“键:%.*s\n”,
(int)rkm->key_len,(const char*)rkm->key;
否则如果(rkm->键)
printf(“键:(%d字节)\n”,(int)rkm->Key\u len);
如果(rkm->有效载荷)
printf(“值:%.*s\n”,
(int)rkm->len,(常量字符*)rkm->payload);
否则如果(rkm->键)
printf(“值:(%d字节)\n”,(int)rkm->len);
rd_kafka_commit_消息(rk,rkm,0);
卡夫卡消息销毁(rkm);
运行计数器++;
}
fprintf(stderr,%%关闭使用者\n”);
卡夫卡消费者研究中心(rk);
卡夫卡(rk);
返回0;
}
我知道这里有一个类似问题的答案 但这没有帮助。我将主题分区列表分配给
再平衡\u cb
中的消费者

更新:

这是示例2消息的输出:

> %4|1580198390.566|CONFWARN|rdkafka#consumer-1| [thrd:app]: Configuration property offset.store.method is deprecated: Offset commit store method: 'file' - DEPRECATED: local file store (offset.store.path, et.al), 'broker' - broker commit store (requires Apache Kafka 0.8.2 or later on the broker).

> % Subscribed to 1 topic(s), waiting for rebalance and messages...

> % Consumer group rebalanced: assigned:
> NewTestingTopic [0] offset -1001, NewTestingTopic [1] offset -1001, 
> NewTestingTopic [2] offset -1001, NewTestingTopic [3] offset -1001
> NewTestingTopic [0] offset -1001, NewTestingTopic [1] offset -1001, 
> NewTestingTopic [2] offset -1001, NewTestingTopic [3] offset -1001
> 
> Message on NewTestingTopic [0] at offset 25:
> Key: 0
> Value: ExampleMessage 0
> 
> NewTestingTopic [0] offset -1001, NewTestingTopic [1] offset -1001, 
> NewTestingTopic [2] offset -1001, NewTestingTopic [3] offset -1001
> 
> Message on NewTestingTopic [3] at offset 41:
> Key: 1
> Value: ExampleMessage 1

我相信这可能是故意的

rd_kafka_assignment()
方法返回通过
rd_kafka_assign()
提供的赋值。在组中为使用者分配分区时