From 37bdf56862da6c583c4d4cb65f3c30b1673025f4 Mon Sep 17 00:00:00 2001 From: BryantHe Date: Fri, 21 Jul 2023 15:37:41 +0800 Subject: [PATCH] chore: add demo --- namekoplus/command.py | 2 +- namekoplus/templates/all/config.yml | 3 ++- namekoplus/templates/demo/__init__.py | 0 namekoplus/templates/demo/config.yml | 5 +++++ namekoplus/templates/demo/rpc_demo.py | 20 ++++++++++++++++++++ namekoplus/templates/event/config.yml | 2 +- namekoplus/templates/http/config.yml | 3 ++- namekoplus/templates/rpc/config.yml | 2 +- namekoplus/templates/timer/config.yml | 2 +- setup.py | 2 +- 10 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 namekoplus/templates/demo/__init__.py create mode 100644 namekoplus/templates/demo/config.yml create mode 100644 namekoplus/templates/demo/rpc_demo.py diff --git a/namekoplus/command.py b/namekoplus/command.py index 8d6844c..bed5b5a 100644 --- a/namekoplus/command.py +++ b/namekoplus/command.py @@ -68,7 +68,7 @@ def cli(): @click.option('-t', '--type', '_type', default='all', show_default=True, - type=click.Choice(['all', 'rpc', 'event', 'http', 'timer'], case_sensitive=False), + type=click.Choice(['all', 'rpc', 'event', 'http', 'timer', 'demo'], case_sensitive=False), help='The template type of nameko service') def init(directory, _type): """ diff --git a/namekoplus/templates/all/config.yml b/namekoplus/templates/all/config.yml index f8f8f3e..a468f6d 100644 --- a/namekoplus/templates/all/config.yml +++ b/namekoplus/templates/all/config.yml @@ -1,4 +1,5 @@ -AMQP_URI: pyamqp://${RABBIT_USER:guest}:${RABBIT_PASSWORD:guest}@${RABBIT_HOST:localhost}:${RABBIT_PORT:5672}/ +AMQP_URI: pyamqp://${RABBIT_USER:admin}:${RABBIT_PASSWORD:admin}@${RABBIT_HOST:localhost}:${RABBIT_PORT:5672}/ +WEB_SERVER_ADDRESS: '0.0.0.0:8000' RPC_EXCHANGE: 'nameko-rpc' max_workers: 10 diff --git a/namekoplus/templates/demo/__init__.py b/namekoplus/templates/demo/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/namekoplus/templates/demo/config.yml b/namekoplus/templates/demo/config.yml new file mode 100644 index 0000000..1a0ee3b --- /dev/null +++ b/namekoplus/templates/demo/config.yml @@ -0,0 +1,5 @@ +AMQP_URI: pyamqp://${RABBIT_USER:admin}:${RABBIT_PASSWORD:admin}@${RABBIT_HOST:localhost}:${RABBIT_PORT:5672}/ +RPC_EXCHANGE: 'nameko-rpc' + +max_workers: 10 +parent_calls_tracked: 20 diff --git a/namekoplus/templates/demo/rpc_demo.py b/namekoplus/templates/demo/rpc_demo.py new file mode 100644 index 0000000..843d1a7 --- /dev/null +++ b/namekoplus/templates/demo/rpc_demo.py @@ -0,0 +1,20 @@ +from nameko.rpc import rpc, ServiceRpc + + +class RpcResponderDemoService: + name = "rpc_responder_demo_service" + + @rpc + def hello(self, name): + return "Hello, {}!".format(name) + + +class RpcCallerDemoService: + name = "rpc_caller_demo_service" + + remote = ServiceRpc("rpc_responder_demo_service") + + @rpc + def remote_hello(self, value="John Doe"): + res = u"{}".format(value) + return self.remote.hello(res) diff --git a/namekoplus/templates/event/config.yml b/namekoplus/templates/event/config.yml index f8f8f3e..b77efe0 100644 --- a/namekoplus/templates/event/config.yml +++ b/namekoplus/templates/event/config.yml @@ -1,4 +1,4 @@ -AMQP_URI: pyamqp://${RABBIT_USER:guest}:${RABBIT_PASSWORD:guest}@${RABBIT_HOST:localhost}:${RABBIT_PORT:5672}/ +AMQP_URI: pyamqp://${RABBIT_USER:admin}:${RABBIT_PASSWORD:admin}@${RABBIT_HOST:localhost}:${RABBIT_PORT:5672}/ RPC_EXCHANGE: 'nameko-rpc' max_workers: 10 diff --git a/namekoplus/templates/http/config.yml b/namekoplus/templates/http/config.yml index f8f8f3e..a468f6d 100644 --- a/namekoplus/templates/http/config.yml +++ b/namekoplus/templates/http/config.yml @@ -1,4 +1,5 @@ -AMQP_URI: pyamqp://${RABBIT_USER:guest}:${RABBIT_PASSWORD:guest}@${RABBIT_HOST:localhost}:${RABBIT_PORT:5672}/ +AMQP_URI: pyamqp://${RABBIT_USER:admin}:${RABBIT_PASSWORD:admin}@${RABBIT_HOST:localhost}:${RABBIT_PORT:5672}/ +WEB_SERVER_ADDRESS: '0.0.0.0:8000' RPC_EXCHANGE: 'nameko-rpc' max_workers: 10 diff --git a/namekoplus/templates/rpc/config.yml b/namekoplus/templates/rpc/config.yml index f8f8f3e..b77efe0 100644 --- a/namekoplus/templates/rpc/config.yml +++ b/namekoplus/templates/rpc/config.yml @@ -1,4 +1,4 @@ -AMQP_URI: pyamqp://${RABBIT_USER:guest}:${RABBIT_PASSWORD:guest}@${RABBIT_HOST:localhost}:${RABBIT_PORT:5672}/ +AMQP_URI: pyamqp://${RABBIT_USER:admin}:${RABBIT_PASSWORD:admin}@${RABBIT_HOST:localhost}:${RABBIT_PORT:5672}/ RPC_EXCHANGE: 'nameko-rpc' max_workers: 10 diff --git a/namekoplus/templates/timer/config.yml b/namekoplus/templates/timer/config.yml index f8f8f3e..b77efe0 100644 --- a/namekoplus/templates/timer/config.yml +++ b/namekoplus/templates/timer/config.yml @@ -1,4 +1,4 @@ -AMQP_URI: pyamqp://${RABBIT_USER:guest}:${RABBIT_PASSWORD:guest}@${RABBIT_HOST:localhost}:${RABBIT_PORT:5672}/ +AMQP_URI: pyamqp://${RABBIT_USER:admin}:${RABBIT_PASSWORD:admin}@${RABBIT_HOST:localhost}:${RABBIT_PORT:5672}/ RPC_EXCHANGE: 'nameko-rpc' max_workers: 10 diff --git a/setup.py b/setup.py index 3fc3c41..7ad470b 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ with open(path.join(here, 'README.md'), encoding='utf-8') as f: setup( name='namekoplus', - version='0.2.0', + version='0.2.1', description='A lightweight Python distributed microservice solution', long_description=long_description, long_description_content_type='text/markdown',