您的位置:首页 > 其它

关于librdkafka设置手动提交

2017-08-02 18:37 495 查看
需同时使用globalconf的conf->set("enable.auto.commit", "false", errstr);

以及tconf的tconf->set("auto.offset.reset", "earliest", errstr); // 注意,earliest与latest是有区别的,先看官网解释:

auto.offset.resetCsmallest, earliest, beginning, largest, latest, end, errorlargestAction to take when there is no initial offset in offset store or the desired offset is out of range: 'smallest','earliest' - automatically reset the offset to the smallest offset, 'largest','latest'
- automatically reset the offset to the largest offset, 'error' - trigger an error which is retrieved by consuming messages and checking 'message->err'. 
Type: enum value
然后是真实含义:

earliest 
当各分区下有已提交的offset时,从提交的offset开始消费;无提交的offset时,从头开始消费 
latest 
当各分区下有已提交的offset时,从提交的offset开始消费;无提交的offset时,消费新产生的该分区下的数据 
none 
topic各分区都存在已提交的offset时,从offset后开始消费;只要有一个分区不存在已提交的offset,则抛出异常

所以earliest和latest是有区别的。

在我的场景中就配置为本文最上面的两行就行了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: