0

I am using websockets and asyncio for a python client to get data from another service. I have a different frontend service that subscribes to the same channel and gets the latest data in ~20sec, but when calling using this client, the latest data is on a ~10 minute delay (it eventually comes). Any issues with my implementation that would cause a buffer or a delay in receiving data?

class StreamAPI:

    def __init__(self, token, channel, uuid, vendor):
        self.token = token
        self.url = "wss://stream.mystreamapi.com"
        # self.loop = asyncio.get_event_loop()
        self.subscription = {'type': 'SUBSCRIBE'}
        self.subscription.update({"channel": channel})

    def get_response(self):
        # return self.loop.run_until_complete(self.async__get_status())
        return asyncio.run(self.async__get_status())

    @retry(TimeoutError, tries=3, logger=None)
    async def async__get_status(self):
        async with websockets.connect(self.url, subprotocols=["accessToken", self.token, "keepAlive"]) as ws:
            await ws.send(json.dumps(self.subscription))
            response = await ws.recv()
            return response

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.