websockets icon indicating copy to clipboard operation
websockets copied to clipboard

why does my WS server accept only 1 connection

Open dsun-ge opened this issue 7 years ago • 2 comments

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()

dsun-ge avatar Jun 14 '19 14:06 dsun-ge

Probably because next(kafka_consumer) blocks.

aaugustin avatar Jun 15 '19 08:06 aaugustin

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.

aaugustin avatar Jun 22 '19 16:06 aaugustin