Skip to content

Commit 4ee3649

Browse files
sparkingdarkmiguelgrinberg
authored andcommitted
Support multiple Kafka servers
1 parent 3bd1357 commit 4ee3649

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/socketio/kafka_manager.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ class KafkaManager(PubSubManager): # pragma: no cover
2424
server = socketio.Server(client_manager=socketio.KafkaManager(url))
2525
2626
:param url: The connection URL for the Kafka server. For a default Kafka
27-
store running on the same host, use ``kafka://``.
27+
store running on the same host, use ``kafka://``. For a highly
28+
available deployment of Kafka, pass a list with all the
29+
connection URLs available in your cluster.
2830
:param channel: The channel name (topic) on which the server sends and
2931
receives notifications. Must be the same in all the
3032
servers.
@@ -44,10 +46,12 @@ def __init__(self, url='kafka://localhost:9092', channel='socketio',
4446
super(KafkaManager, self).__init__(channel=channel,
4547
write_only=write_only)
4648

47-
self.kafka_url = url[8:] if url != 'kafka://' else 'localhost:9092'
48-
self.producer = kafka.KafkaProducer(bootstrap_servers=self.kafka_url)
49+
urls = [url] if isinstance(url, str) else url
50+
self.kafka_urls = [url[8:] if url != 'kafka://' else 'localhost:9092'
51+
for url in urls]
52+
self.producer = kafka.KafkaProducer(bootstrap_servers=self.kafka_urls)
4953
self.consumer = kafka.KafkaConsumer(self.channel,
50-
bootstrap_servers=self.kafka_url)
54+
bootstrap_servers=self.kafka_urls)
5155

5256
def _publish(self, data):
5357
self.producer.send(self.channel, value=pickle.dumps(data))

0 commit comments

Comments
 (0)