Example #1
0
async def reader(message_queue: aioredis.Channel, game_id: str) -> None:
    global channels

    logger.info(f"Started listening to {game_id}")
    async for message in message_queue.iter(encoding="utf-8"):
        logger.info(f"Broadcasting to {game_id}: {str(message)}")
        for websocket in channels[game_id]:
            await websocket.send(str(message))
    logger.info(f"Stopped listening to {game_id}")
Example #2
0
    async def _receive_on_channel(self, channel: Channel):
        log.debug("({cls}) running message receive for '%s'",
                  channel.name,
                  extra=self._fmtargs)
        async for topic, message in channel.iter():
            log.debug("({cls}) received message in topic channel %s",
                      topic,
                      extra=self._fmtargs)
            try:
                parsed_message = pickle.loads(message, encoding="utf-8")
                await self._dispatch_processor(parsed_message)

            except Exception:
                log.exception(
                    "failed to parse message and dispatch its processor, continuing"
                )
Example #3
0
async def reader(channel: Channel, socket: WebSocket) -> None:
    async for message in channel.iter():
        await socket.send_text(message.decode('utf-8'))
 async def reader(channel: aioredis.Channel):
     async for msg in channel.iter():
         print(f'msg: {msg.decode()}')
         await socket_manager.broadcast(None, msg.decode())