From a04b078513dbcb09083f9275dab852158e85f7bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Mon, 30 Jul 2018 09:25:32 +0200 Subject: [PATCH] Implement message sequence numbers in ZMQWSProxy --- lib/tfw/networking/server/zmq_websocket_proxy.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/tfw/networking/server/zmq_websocket_proxy.py b/lib/tfw/networking/server/zmq_websocket_proxy.py index 6df7c9a..5ab0b10 100644 --- a/lib/tfw/networking/server/zmq_websocket_proxy.py +++ b/lib/tfw/networking/server/zmq_websocket_proxy.py @@ -14,6 +14,7 @@ LOG = logging.getLogger(__name__) class ZMQWebSocketProxy(WebSocketHandler): # pylint: disable=abstract-method instances = set() + sequence_number = 0 def initialize(self, **kwargs): # pylint: disable=arguments-differ self._event_handler_connector = kwargs['event_handler_connector'] @@ -59,14 +60,20 @@ class ZMQWebSocketProxy(WebSocketHandler): """ Invoked on ZMQ messages from event handlers. """ + self.sequence_message(message) LOG.debug('Received on pull socket: %s', message) self.proxy_eventhandler_to_websocket(message) + def sequence_message(self, message): + self.sequence_number += 1 + message['seq'] = self.sequence_number + def on_message(self, message): """ Invoked on WS messages from frontend. """ message = json.loads(message) + self.sequence_message(message) LOG.debug('Received on WebSocket: %s', message) self.proxy_websocket_to_eventhandler(message)