python脚本如下:
from kafka import KafkaProducer import ssl # Kafka 服务器地址,替换为你的kafka地址和端口 bootstrap_servers = 'ip:port' # SSL 配置 ssl_context = ssl.create_default_context() ssl_context.check_hostname = False ssl_context.verify_mode = ssl.CERT_NONE # Kafka 生产者配置 producer = KafkaProducer( bootstrap_servers=bootstrap_servers, security_protocol='SASL_PLAINTEXT', sasl_mechanism='PLAIN', sasl_plain_username='username', # 替换为你的用户名 sasl_plain_password='password', # 替换为你的密码 ssl_context=ssl_context ) # 要发送的消息和主题 topic = 'topic' # 替换为你的 Kafka 主题名称 message = 'Hello, Kafka!' # 替换为你要发送的消息 # 发送消息 producer.send(topic, message.encode('utf-8')) # 等待所有消息发送完成 producer.flush() print(f"Message '{message}' sent to topic '{topic}'")