def onMessage(self, payload, isBinary): # noqa try: s = json.loads(payload.decode('utf8')) except ValueError as e: logger.warning('got a bogus payload from %s: %s', self, e) return # handle subscriptions if 'subscribe' in s: PubSubManager.instance().subscribe(self, s['subscribe']) # respond with the latest data from this topic PubSubManager.instance().publish_one(self, s['subscribe']) # handle unsubscriptions if 'unsubscribe' in s: PubSubManager.instance().unsubscribe(self, s['unsubscribe']) # handle requests if 'request' in s: response = RequestHandler.instance().handle(s) self.send(s['request'], response)
def onMessage(self, payload, isBinary): try: s = json.loads(payload.decode('utf8')) except ValueError as e: logger.warning('got a bogus payload from %s: %s', self, e) return # handle subscriptions if 'subscribe' in s: PubSubManager.instance().subscribe(self, s['subscribe']) # respond with the latest data from this topic PubSubManager.instance().publish_one(self, s['subscribe']) # handle unsubscriptions if 'unsubscribe' in s: PubSubManager.instance().unsubscribe(self, s['unsubscribe']) # handle requests if 'request' in s: response = RequestHandler.instance().handle(s) self.send(s['request'], response)
def publish(topic): while True: PubSubManager.instance().publish(topic) yield from asyncio.sleep(topic.sleep)
def test_all(self, new): PubSubManager.instance() PubSubManager.instance() self.assertEqual(new.call_count, 1)
def onClose(self, wasClean, code, reason): logger.info('connection closed for %s: %s', self, reason) PubSubManager.instance().unsubscribe_all(self)
def test_all(self, new): PubSubManager.instance() PubSubManager.instance() self.assertEqual(new.call_count, 1)
async def publish(topic): while True: PubSubManager.instance().publish(topic) await asyncio.sleep(topic.sleep)
def onClose(self, wasClean, code, reason): # noqa logger.info('connection closed for %s: %s', self, reason) PubSubManager.instance().unsubscribe_all(self)