websockets
websockets copied to clipboard
why does my WS server accept only 1 connection
I am trying to build a server that consumes Kafka messages and then sends the messages to websocket client. My code is below. It only accepts the first connection. Why?
kafka_consumer = KafkaConsumer(
'etrm-notification',
bootstrap_servers=[server],
auto_offset_reset='earliest',
enable_auto_commit=True,
group_id='group1',
value_deserializer=lambda x: loads(x.decode('utf-8')))
@asyncio.coroutine
async def notification(websocket, path):
# register(websocket) sends user_event() to websocket
for msg in kafka_consumer:
await websocket.send(json.dumps(msg.value))
asyncio.get_event_loop().run_until_complete(
websockets.serve(notification, '0.0.0.0', 8081))
asyncio.get_event_loop().run_forever()
Probably because next(kafka_consumer) blocks.
Since you didn't follow up, I'm going to close this.
Please let me know if you think there's a bug in websockets.