python kafka權限校驗client.id


kafka集群有權限校驗,在連接時需要加入client.id。但pykafka不能配置該選項。搜索了一下,需要使用confluent-kafka

鏈接: https://blog.csdn.net/lanyang123456/article/details/80639625

#coding:utf-8

from confluent_kafka import Consumer, KafkaError

mybroker = "127.0.0.1:9092"  #host
client_id = "校驗id"
my_topic = "你的topic"

c = Consumer({
    'bootstrap.servers': mybroker,
    'group.id': 'mygroup',
    'client.id': client_id ,
    'default.topic.config': {
    'auto.offset.reset': 'smallest'
    }
})

c.subscribe([my_topic])

while True:
    msg = c.poll(1.0)

    if msg is None:
        continue
    if msg.error():
        if msg.error().code() == KafkaError._PARTITION_EOF:
            continue
        else:
            print(msg.error())
            break

    print('Received message: {}'.format(msg.value().decode('utf-8')))

c.close()


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM