Implement message sequence numbers in ZMQWSProxy

This commit is contained in:
Kristóf Tóth 2018-07-30 09:25:32 +02:00
parent d94bc37d48
commit a04b078513

View File

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