From 03082b346d884a1295a03a45dd1ce3fb20a7b830 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Fri, 17 Apr 2020 16:59:35 +0200 Subject: [PATCH] send uuid with message --- app.py | 2 +- messagesender.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index bebb909..7055f86 100644 --- a/app.py +++ b/app.py @@ -40,7 +40,7 @@ if __name__ == "__main__": communicator = Communicator(currentconsumer=KNOWNCONSUMER, uuid=generateduuid) LOGGER.debug(f"My uuid is {generateduuid}") consumerlocator = ConsumerLocator(uuid=generateduuid, communicator=communicator) - messagesender = MessageSender(communicator=communicator) + messagesender = MessageSender(communicator=communicator, uuid=generateduuid) consumerlocator.learnconsumerlist() while True: diff --git a/messagesender.py b/messagesender.py index a7ea607..e5e7db1 100644 --- a/messagesender.py +++ b/messagesender.py @@ -7,6 +7,7 @@ Message sender component. import logging import random import string +import json from communicator import Communicator __author__ = "@kovacsbence" @@ -23,13 +24,14 @@ class MessageSender: Component responsible for sending the messages. Requires an instance of :class:`communicator.Communicator`. """ - def __init__(self, communicator: Communicator): + def __init__(self, communicator: Communicator, uuid: str): """**Constructor:** Initializes the object. :param communicator: an instance of :class:`communicator.Communicator`. """ self.communicator = communicator + self.uuid = uuid def randomstring(self, stringlength: int) -> str: """Generate a random string of fixed length @@ -54,4 +56,4 @@ class MessageSender: data = self.randomstring(32) else: data = message - self.communicator.sendmessage(data) + self.communicator.sendmessage(json.dumps({"message": data, "uuid": self.uuid}))