[英]enable_auto_commit=False, but still offsets are committed automatically
I'm using kafka-python==2.0.2
, and have disabled auto_commit
but still if I don't commit through code, offsets are automatically getting committed我正在使用
kafka-python==2.0.2
,并禁用了auto_commit
但如果我不通过代码提交,偏移量会自动提交
In the below code even if I comment out self.consumer.commit_async(callback=....
, offsets are still getting committed在下面的代码中,即使我注释掉
self.consumer.commit_async(callback=....
,偏移量仍在提交
class KafkaMessageConsumer:
def __init__(self, bootstrap_servers: str, topic: str, group_id: str, offset_reset_strategy: str):
self.bootstrap_servers: str = bootstrap_servers
self.topic: str = topic
self.group_id: str = group_id
self.consumer: KafkaConsumer = KafkaConsumer(topic, bootstrap_servers=bootstrap_servers, group_id=group_id,
enable_auto_commit=False, auto_offset_reset=offset_reset_strategy)
def consume_messages(self, consumer_poll_timeout: int, max_poll_records: int,
message_handler: MessageHandlerImpl = MessageHandlerImpl()):
try:
while True:
try:
msg_pack = self.consumer.poll(timeout_ms=consumer_poll_timeout, max_records=max_poll_records)
if bool(msg_pack):
for topic_partition, messages in msg_pack.items():
message_handler.process_messages(messages)
self.consumer.commit_async(callback=(lambda offsets, response: log.error(
f"Error while committing offset in async due to: {response}", exc_info=True) if isinstance(
response, Exception) else log.debug(f"Successfully committed offsets: {offsets}")))
except Exception as e:
log.error(f"Error while consuming/processing message due to: {e}", exc_info=True)
finally:
log.error("Something went wrong, closing consumer...........")
self.consumer.close()
Is this a proper way to disable auto commit and commit manually?这是禁用自动提交和手动提交的正确方法吗?
poll()
always moves forward, regardless of committing. poll()
总是向前移动,不管是否提交。 It just does not write offsets back to Kafka .它只是不将偏移量写回 Kafka 。
If you restart your app , then would it pickup the same data again and again.如果您重新启动您的应用程序,那么它会一次又一次地获取相同的数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.