简体   繁体   English

在 Python 上的服务器之间发送数据 Kafka Apache

[英]Send data between servers Kafka Apache on Python

producer = KafkaProducer(bootstrap_servers='kf-p1l-node3:9092,xxxxx,xxxxx',
                                 value_serializer=lambda x: dumps(x).encode('utf-8'))  # utf-8
consumer = KafkaConsumer(  bootstrap_servers='rdwh-node1:49092,xxxxx,xxxxx',
                                 # bootstrap_servers='kf-p1l-node3:9092,xxxxx,xxxxx',
                                 auto_offset_reset=param["AUTO_OFFSET_RESET"],
                                 consumer_timeout_ms=param["CONSUMER_TIMEOUT_MS"],
                                 enable_auto_commit=False,
                                 auto_commit_interval_ms=60000,
                                 group_id=param["GROUP_ID"],
                                 client_id=param["CLIENT_ID"]
                                 )
consumer.subscribe([param["TOPIC_IN"]])

This code work if, KafkaProducer and KafkaConsumer's bootstrap_server are the same.如果 KafkaProducer 和 KafkaConsumer 的 bootstrap_server 相同,则此代码有效。 But if change KafkaConsumer to another server it doesn't work但是如果将 KafkaConsumer 更改为另一台服务器,它就不起作用

Bootstrap servers must contain all servers for establishing the initial connection to the Kafka cluster.引导服务器必须包含所有用于建立与 Kafka 集群的初始连接的服务器。 The client will make use of all servers irrespective of which servers are specified here for bootstrapping.客户端将使用所有服务器,而不管此处为引导指定了哪些服务器。 You can check the documentation here: http://kafka.apache.org/090/documentation.html您可以在此处查看文档: http://kafka.apache.org/090/documentation.html

consumer = KafkaConsumer('my-topic',
                         group_id='my-group',
                         bootstrap_servers=['node1:port1', 'node1:port2', 'node2:port3'])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM