Kafka 客户端需要使用 SASL 进行身份验证以确保数据的安全性。有关 SASL_PLAINTEXT 的工作原理如下: usesKafkaClient+connect()+send()+receive()SASLAuth+authenticate()+getCredentials() 通过SASL_PLAINTEXT 协议,Kafka 客户端在进行连接时,使用用户名和密码进行身份验证。虽然 SASL_PLAINTEXT 提供基本的安全性,但...
在连接到Kafka之前,你需要配置SASL认证所需的参数,包括Kafka集群的地址、安全协议、SASL机制、用户名和密码等。 编写Python代码以创建Kafka生产者或消费者实例: 下面是一个使用confluent-kafka-python库连接Kafka并发送消息的示例代码: python from confluent_kafka import Producer import json # 配置Kafka生产者 conf ...
:param sasl_mechanism: 为"PLAIN"时使用账号密码,默认为None :param username: 用户名 :param password: 密码 :param security_protocol: PLAINTEXT, SSL, SASL_PLAINTEXT, SASL_SSL, 默认为PLAINTEXT。 SSL:使用ssl认证,,【ssl_cafile,ssl_certfile,ssl_keyfile】为必传。 SASL_PLAINTEXT: 使用账号,密码 :...
producer= KafkaProducer(sasl_mechanism='PLAIN', security_protocol='SASL_PLAINTEXT', sasl_plain_username='xxxxx', sasl_plain_password='xxxxxxxx', bootstrap_servers=['xxxxxxxxxxx'],#这里的dumps可以指定ensure_ascii=Falsevalue_serializer=lambdam: json.dumps(m,ensure_ascii=False).encode(), api_versi...
security_protocol="SASL_PLAINTEXT"sasl_mechanism="PLAIN"sasl_plain_username=config.USERNAMEsasl_plain_password=config.PASSWORD 这四个参数是因为我这里需要通过密码连接 Kafka 而加上的,如果你的 Kafka 没有账号密码,就不需要这四个参数。 创建消费者 ...
pip install confluent_kafka 生产端示例代码 import json from datetime import datetime from confluent_kafka import Producer topic_name = 'python_test' conf = { 'bootstrap.servers': '10.110.18.214:8911,10.110.16.96:8911,10.110.19.242:8911', 'security.protocol': 'SASL_PLAINTEXT', 'sasl.mechanisms...
security_protocol="SASL_PLAINTEXT"sasl_mechanism="PLAIN"sasl_plain_username=config.USERNAME sasl_plain_password=config.PASSWORD 这四个参数是因为我这里需要通过密码连接 Kafka 而加上的,如果你的 Kafka 没有账号密码,就不需要这四个参数。 创建消费者 ...
class KafkaTookit(): def __init__(self, config=Config.KAFKA): self.topic = config["topic"] if config["sasl"]: self.producer = KafkaProducer( sasl_mechanism="PLAIN", security_protocol='SASL_PLAINTEXT', sasl_plain_username=config["username"], ...
producer=KafkaProducer( bootstrap_servers=['xx.xx.xx.xx:port'],#地址 api_version=(1,1), security_protocol="SASL_PLAINTEXT", sasl_mechanism="PLAIN", sasl_plain_username="username",#用户名 sasl_plain_password="password",#密码 ) ...
security_protocol="SASL_PLAINTEXT" sasl_mechanism="PLAIN" sasl_plain_username=config.USERNAME sasl_plain_password=config.PASSWORD 这四个参数是因为我这里需要通过密码连接 Kafka 而加上的,如果你的 Kafka 没有账号密码,就不需要这四个参数。 创建消费者 ...