From 234b3f366eb148d50187a53486017a30c26e6c97 Mon Sep 17 00:00:00 2001 From: TheBurchLog <5104941+TheBurchLog@users.noreply.github.com> Date: Tue, 7 Nov 2023 20:18:08 +0000 Subject: [PATCH] Adding Pub/Sub examples --- publisher/beer.conf | 1 + publisher/publisher/__init__.py | 0 publisher/publisher/__main__.py | 28 ++++++++++++++++++++++ publisher/setup.py | 41 +++++++++++++++++++++++++++++++++ subscribe/beer.conf | 1 + subscribe/setup.py | 41 +++++++++++++++++++++++++++++++++ subscribe/subscribe/__init__.py | 0 subscribe/subscribe/__main__.py | 33 ++++++++++++++++++++++++++ 8 files changed, 145 insertions(+) create mode 100644 publisher/beer.conf create mode 100644 publisher/publisher/__init__.py create mode 100644 publisher/publisher/__main__.py create mode 100644 publisher/setup.py create mode 100644 subscribe/beer.conf create mode 100644 subscribe/setup.py create mode 100644 subscribe/subscribe/__init__.py create mode 100644 subscribe/subscribe/__main__.py diff --git a/publisher/beer.conf b/publisher/beer.conf new file mode 100644 index 0000000..1030677 --- /dev/null +++ b/publisher/beer.conf @@ -0,0 +1 @@ +PLUGIN_ENTRY="-m publisher" diff --git a/publisher/publisher/__init__.py b/publisher/publisher/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/publisher/publisher/__main__.py b/publisher/publisher/__main__.py new file mode 100644 index 0000000..9f50898 --- /dev/null +++ b/publisher/publisher/__main__.py @@ -0,0 +1,28 @@ +import logging + +from brewtils import PublishClient, Plugin, command + +__version__ = "3.0.0.dev0" + +class Publisher: + + def __init__(self): + self.publishClient = publishClient + + @command() + def publish_topics(self, payload:dict, topic:str = "topic1") -> dict: + return dict + +def main(): + plugin = Plugin( + name="publisher", + version=__version__, + description="A plugin that publishes to topics", + max_concurrent=1, + ) + plugin.client = Publisher() + plugin.run() + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/publisher/setup.py b/publisher/setup.py new file mode 100644 index 0000000..422ee27 --- /dev/null +++ b/publisher/setup.py @@ -0,0 +1,41 @@ +import re + +from setuptools import setup + + +def find_version(version_file): + version_line = open(version_file, "rt").read() + match_object = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", version_line, re.M) + + if not match_object: + raise RuntimeError("Unable to find version string in %s" % version_file) + + return match_object.group(1) + + +setup( + name="publisher", + version=find_version("publisher/__main__.py"), + description="A plugin that publishes to topics", + url="https://beer-garden.io", + author="The Beergarden Team", + author_email=" ", + license="MIT", + packages=["publisher"], + install_requires=["brewtils"], + classifiers=[ + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 2", + "Programming Language :: Python :: 2.7", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.5", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + ], +) diff --git a/subscribe/beer.conf b/subscribe/beer.conf new file mode 100644 index 0000000..a0b1670 --- /dev/null +++ b/subscribe/beer.conf @@ -0,0 +1 @@ +PLUGIN_ENTRY="-m subscribe" diff --git a/subscribe/setup.py b/subscribe/setup.py new file mode 100644 index 0000000..aca0e3d --- /dev/null +++ b/subscribe/setup.py @@ -0,0 +1,41 @@ +import re + +from setuptools import setup + + +def find_version(version_file): + version_line = open(version_file, "rt").read() + match_object = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", version_line, re.M) + + if not match_object: + raise RuntimeError("Unable to find version string in %s" % version_file) + + return match_object.group(1) + + +setup( + name="subscribe", + version=find_version("subscribe/__main__.py"), + description="A plugin that subscribes to topics", + url="https://beer-garden.io", + author="The Beergarden Team", + author_email=" ", + license="MIT", + packages=["subscribe"], + install_requires=["brewtils"], + classifiers=[ + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 2", + "Programming Language :: Python :: 2.7", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.5", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + ], +) diff --git a/subscribe/subscribe/__init__.py b/subscribe/subscribe/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/subscribe/subscribe/__main__.py b/subscribe/subscribe/__main__.py new file mode 100644 index 0000000..52ac0a1 --- /dev/null +++ b/subscribe/subscribe/__main__.py @@ -0,0 +1,33 @@ +import logging + +from brewtils import subscribe, Plugin + +__version__ = "3.0.0.dev0" + +class SubscribeClient: + + @subscribe(topics=["topic1","topic2"]) + def subscribe_multiple_topics(self, payload:dict) -> dict: + return dict + + @subscribe(topics="topic1") + def subscrib_one_topics(self, payload:dict) -> dict: + return dict + + @subscribe(topics="topic.*") + def subscribe_wildcard_topics(self, payload:dict) -> dict: + return dict + +def main(): + plugin = Plugin( + name="subscribe", + version=__version__, + description="A plugin that subscribes to topics", + max_concurrent=1, + ) + plugin.client = SubscribeClient() + plugin.run() + + +if __name__ == "__main__": + main() \ No newline at end of file