From f79bdc02e50fae1ea37ca1e7744e62d215d1ef24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kov=C3=A1cs=20Bence?= Date: Sun, 29 Mar 2020 15:24:45 +0200 Subject: [PATCH 1/4] MessageSender skeleton --- MessageSender.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 MessageSender.py diff --git a/MessageSender.py b/MessageSender.py new file mode 100644 index 0000000..bbdd150 --- /dev/null +++ b/MessageSender.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python +import sentry_sdk +import json +import random + +class MessageSender: + data = { + "packet name" : "name", + "data" : random.randrange(100000) + } + + message = json.dumps(data) + + + +if __name__ == "__main__": + print("Producer") + message = MessageSender() + print(message.message) \ No newline at end of file From 1b95e0828568af3c766a31e6fbb81c4e5dc8a0fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Sun, 29 Mar 2020 15:46:00 +0200 Subject: [PATCH 2/4] add requests requirements --- communicator.py | 10 ++++++++++ requirements.txt | 1 + 2 files changed, 11 insertions(+) create mode 100644 communicator.py diff --git a/communicator.py b/communicator.py new file mode 100644 index 0000000..38b2bf5 --- /dev/null +++ b/communicator.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python + +""" +Main Flask RESTful API +""" + +__author__ = "@tormakris" +__copyright__ = "Copyright 2020, GoldenPogácsa Team" +__module_name__ = "messagesender" +__version__text__ = "1" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 5051901..07f9470 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ sentry_sdk +requests \ No newline at end of file From e6f4bbdcfeafc0c8a13f778278260d514daf2981 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Sun, 29 Mar 2020 16:26:16 +0200 Subject: [PATCH 3/4] communicator interface done --- Dockerfile | 2 +- communicator.py | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index a551683..0ca2e4e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,4 +6,4 @@ COPY . ./ RUN pip3 install --no-cache-dir -r requirements.txt -CMD ["python3" "app.py"] +CMD ["python3", "app.py"] diff --git a/communicator.py b/communicator.py index 38b2bf5..4c8b585 100644 --- a/communicator.py +++ b/communicator.py @@ -1,5 +1,7 @@ #!/usr/bin/env python +import requests + """ Main Flask RESTful API """ @@ -7,4 +9,36 @@ Main Flask RESTful API __author__ = "@tormakris" __copyright__ = "Copyright 2020, GoldenPogácsa Team" __module_name__ = "messagesender" -__version__text__ = "1" \ No newline at end of file +__version__text__ = "1" + +class Communicator: + """ + Class handling low level communication with consumers. + """ + def __init__(self): + """ + Initalize class + """ + pass + + def sendmessage(self, message: str) -> None: + """ + Send message to consumer. + :param message: + :return: none + """ + pass + + def discoveravailableconsumers(self) -> list: + """ + Get the list of available consumer from the current primary consumer. + :return: + """ + pass + + def isconsumeravailable(self) -> bool: + """ + Readiness probe primary consumer. + :return: + """ + pass \ No newline at end of file From 3e1f331e032f5e0e3650e96db5198beafe9529a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kov=C3=A1cs=20Bence?= Date: Sun, 29 Mar 2020 16:33:18 +0200 Subject: [PATCH 4/4] MessageSender skeleton --- messagesender.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/messagesender.py b/messagesender.py index dc57c00..cd81501 100644 --- a/messagesender.py +++ b/messagesender.py @@ -1,6 +1,8 @@ #!/usr/bin/env python -#IDE JÖNNEK IMPORTOK +# IDE JÖNNEK IMPORTOK +import random +import string """ Main Flask RESTful API @@ -15,17 +17,37 @@ class MessageSender: """ Üzenetek küldéséért felelős komponens. """ + id + def __init__(self): """ Inicializálja az osztályt. """ + self.id = 0 pass - def cucc(self, szam: int, szoveg: str) -> str: + + def randomString(self, stringLength): + """Generate a random string of fixed length """ + letters = string.ascii_lowercase + return ''.join(random.choice(letters) for i in range(stringLength)) + + + def CreateMessage(self, p) -> str: """ Ez egy metodus :param szam: :param szoveg: :return: str tipus """ - pass \ No newline at end of file + self.id += random.randrange(10000) + data = self.randomString(p) + + #print(str(self.id) + " " + str(data)) + return str(self.id) + " " + str(data) + pass + + +if __name__ == "__main__": + temp = MessageSender() + print(temp.CreateMessage(20))