赞
踩
kafka设置消息存放时间有两种配置
log.retention.hours=8
from confluent_kafka.admin import AdminClient, NewTopic # Configure Kafka admin client admin_conf = {'bootstrap.servers': 'localhost:9092'} admin_client = AdminClient(admin_conf) # Define topic configuration topic_config = { 'retention.ms': '604800000' # 7 days } # Define topic properties topic_properties = NewTopic( topic='my-topic', num_partitions=1, replication_factor=1, config=topic_config ) # Create topic admin_client.create_topics([topic_properties])
比如topic设置消息保存时间是7天,broker设置保存1天。这种情况下,kafka会在一天后删除消息
为了避免消息在topic设置的到期之前被删除,至少需要保证broker的log retention时间大于等于topic的retention时间
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。