print("开始消费了!!!")
KFK = KafkaConsumer(group_id=test_group_id,
bootstrap_servers=cfg.get('kafka', 'log_brokers').split(','),
enable_auto_commit=True, # 每过一段时间自动提交所有已消费的消息(在迭代时提交)
auto_commit_interval_ms=5000, # 自动提交的周期(毫秒)
)
# KFK.subscribe(['ws-depth'])
# 获取topic主题的分区信息
# print(KFK.partitions_for_topic('ws-depth'))
# 获取当前消费者订阅的主题
# print(KFK.subscription())
# 获取给定分区的第一个偏移量
# print(KFK.beginning_offsets(KFK.assignment())) # 打印 :{}
# 手动为该消费者分配一个topic分区列表
KFK.assign([
# TopicPartition(topic=u'ws-depth', partition=5),
TopicPartition(topic=u'ws-depth', partition=6),
])
# 获取分区的偏移量
offset = KFK.position(TopicPartition(topic=u'ws-depth', partition=6))
print('当前的offset {}'.format(offset))
START_OFFSET = offset if offset else 1
if START_OFFSET:
# KFK.seek(TopicPartition(topic=u'ws-depth', partition=5), 12) # 指定起始offset为12
KFK.seek(TopicPartition(topic=u'ws-depth', partition=6), START_OFFSET) # 可以注册多个分区,此分区从第一条消息开始接收
# 获取给定分区的第一个偏移量
# print(KFK.beginning_offsets(KFK.assignment())) # 打印 :{TopicPartition(topic='ws-depth', partition=6): 0}
# 获取分区的偏移量
print(KFK.position(TopicPartition(topic=u'ws-depth', partition=6)))
else:
KFK.subscribe(['ws-depth'])
pool = ProcessPoolExecutor(script_pool_size)
for msg in KFK:
pool.submit(process_message, msg)
```
```