Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:Kafka使用者偏移量在后台提交_Python_Apache Kafka - Fatal编程技术网

Python:Kafka使用者偏移量在后台提交

Python:Kafka使用者偏移量在后台提交,python,apache-kafka,Python,Apache Kafka,代码: from kafka import KafkaConsumer task_event = TaskEvent() consumer = KafkaConsumer('test',bootstrap_servers=["localhost:9092"],group_id=None, auto_offset_reset='smallest') for msg in consumer: print msg.offset 0 1 2 . . 16 输出: from kafka

代码:

from kafka import KafkaConsumer

task_event = TaskEvent()

consumer = KafkaConsumer('test',bootstrap_servers=["localhost:9092"],group_id=None, auto_offset_reset='smallest')
for msg in consumer:
    print msg.offset
0 
1
2 
.
.
16
输出:

from kafka import KafkaConsumer

task_event = TaskEvent()

consumer = KafkaConsumer('test',bootstrap_servers=["localhost:9092"],group_id=None, auto_offset_reset='smallest')
for msg in consumer:
    print msg.offset
0 
1
2 
.
.
16
我在主题
test
中总共有16条消息

-根据公认的答案,您的消费者组1中有一名消费者已消费了5条信息并死亡。下次启动此消费程序时,它甚至不会使用auto.offset.reset配置,并将从其停止的位置继续,因为它只会从偏移存储中获取存储的偏移量

根据Python API文档,默认情况下,
enable_auto_commit
True
,这意味着消费者的偏移量应该在后台提交。但是,当我停止并多次运行上述程序时,我得到的是相同的输出,如果默认情况下
auto_commit
True
(假设任何API的规则都相同,可能是Java或Python)

谢谢。

根据

group_id(str或None)–要加入动态分区分配(如果启用)并用于获取和提交偏移量的使用者组的名称。如果没有,则禁用自动分区分配(通过组协调器)和偏移提交

在我的上述代码中,组id为
None
。我更改了它,并给出了一个组名,并且正在提交偏移量