feat: add new type all
This commit is contained in:
parent
08e818e1e1
commit
8cf674f0df
|
@ -40,10 +40,10 @@ def cli():
|
|||
@click.option('-d', '--directory',
|
||||
required=True,
|
||||
help='The directory name of nameko services')
|
||||
@click.option('-f', '--type', '_type',
|
||||
default='rpc',
|
||||
@click.option('-t', '--type', '_type',
|
||||
default='all',
|
||||
show_default=True,
|
||||
type=click.Choice(['rpc', 'event', 'http', 'timer'], case_sensitive=False),
|
||||
type=click.Choice(['all', 'rpc', 'event', 'http', 'timer'], case_sensitive=False),
|
||||
help='The template type of nameko service')
|
||||
def init(directory, _type):
|
||||
"""
|
||||
|
|
|
@ -0,0 +1,144 @@
|
|||
import json
|
||||
|
||||
from nameko.events import EventDispatcher, event_handler
|
||||
from nameko.rpc import rpc, ServiceRpc
|
||||
from nameko.timer import timer
|
||||
from nameko.web.handlers import http
|
||||
from werkzeug.wrappers import Response
|
||||
from nameko_tracer import Tracer
|
||||
from namekoplus import init_statsd, init_sentry
|
||||
|
||||
|
||||
class HttpDemoService:
|
||||
|
||||
name = "http_demo_service"
|
||||
|
||||
tracer = Tracer()
|
||||
sentry = init_sentry()
|
||||
statsd = init_statsd('statsd_prefix', 'statsd_host', 'statsd_port')
|
||||
|
||||
@http("GET", "/broken")
|
||||
@statsd.timer('broken')
|
||||
def broken(self, request):
|
||||
raise ConnectionRefusedError()
|
||||
|
||||
@http('GET', '/books/<string:uuid>')
|
||||
@statsd.timer('demo_get')
|
||||
def demo_get(self, request, uuid):
|
||||
data = {'id': uuid, 'title': 'The unbearable lightness of being',
|
||||
'author': 'Milan Kundera'}
|
||||
return Response(json.dumps({'book': data}),
|
||||
mimetype='application/json')
|
||||
|
||||
@http('POST', '/books')
|
||||
@statsd.timer('demo_post')
|
||||
def demo_post(self, request):
|
||||
return Response(json.dumps({'book': request.data.decode()}),
|
||||
mimetype='application/json')
|
||||
|
||||
class RpcResponderDemoService:
|
||||
|
||||
name = "rpc_responder_demo_service"
|
||||
|
||||
tracer = Tracer()
|
||||
sentry = init_sentry()
|
||||
statsd = init_statsd('statsd_prefix', 'statsd_host', 'statsd_port')
|
||||
|
||||
@rpc
|
||||
@statsd.timer('hello')
|
||||
def hello(self, name):
|
||||
return "Hello, {}!".format(name)
|
||||
|
||||
|
||||
class RpcCallerDemoService:
|
||||
|
||||
name = "rpc_caller_demo_service"
|
||||
|
||||
remote = ServiceRpc("rpc_responder_demo_service")
|
||||
|
||||
sentry = init_sentry()
|
||||
statsd = init_statsd('statsd_prefix', 'statsd_host', 'statsd_port')
|
||||
|
||||
@rpc
|
||||
@statsd.timer('remote_hello')
|
||||
def remote_hello(self, value="John Doe"):
|
||||
res = u"{}".format(value)
|
||||
return self.remote.hello(res)
|
||||
|
||||
|
||||
class EventPublisherService:
|
||||
|
||||
name = "publisher_service"
|
||||
|
||||
tracer = Tracer()
|
||||
sentry = init_sentry()
|
||||
statsd = init_statsd('statsd_prefix', 'statsd_host', 'statsd_port')
|
||||
|
||||
dispatch = EventDispatcher()
|
||||
|
||||
@rpc
|
||||
@statsd.timer('publish')
|
||||
def publish(self, event_type, payload):
|
||||
self.dispatch(event_type, payload)
|
||||
|
||||
|
||||
class AnEventListenerService:
|
||||
|
||||
name = "an_event_listener_service"
|
||||
|
||||
tracer = Tracer()
|
||||
sentry = init_sentry()
|
||||
statsd = init_statsd('statsd_prefix', 'statsd_host', 'statsd_port')
|
||||
|
||||
@event_handler("publisher_service", "an_event")
|
||||
@statsd.timer('consume_an_event')
|
||||
def consume_an_event(self, payload):
|
||||
print("service {} received:".format(self.name), payload)
|
||||
|
||||
|
||||
class AnotherEventListenerService:
|
||||
|
||||
name = "another_event_listener_service"
|
||||
|
||||
tracer = Tracer()
|
||||
sentry = init_sentry()
|
||||
statsd = init_statsd('statsd_prefix', 'statsd_host', 'statsd_port')
|
||||
|
||||
@event_handler("publisher_service", "another_event")
|
||||
@statsd.timer('consume_another_event')
|
||||
def consume_another_event(self, payload):
|
||||
print("service {} received:".format(self.name), payload)
|
||||
|
||||
|
||||
class ListenBothEventsService:
|
||||
|
||||
name = "listen_both_events_service"
|
||||
|
||||
tracer = Tracer()
|
||||
sentry = init_sentry()
|
||||
statsd = init_statsd('statsd_prefix', 'statsd_host', 'statsd_port')
|
||||
|
||||
@event_handler("publisher_service", "an_event")
|
||||
@statsd.timer('consume_an_event')
|
||||
def consume_an_event(self, payload):
|
||||
print("service {} received:".format(self.name), payload)
|
||||
|
||||
@event_handler("publisher_service", "another_event")
|
||||
@statsd.timer('consume_another_event')
|
||||
def consume_another_event(self, payload):
|
||||
print("service {} received:".format(self.name), payload)
|
||||
|
||||
|
||||
class Timer:
|
||||
|
||||
name = 'timer'
|
||||
|
||||
tracer = Tracer()
|
||||
sentry = init_sentry()
|
||||
statsd = init_statsd('statsd_prefix', 'statsd_host', 'statsd_port')
|
||||
|
||||
@timer(interval=1)
|
||||
@statsd.timer('ping')
|
||||
def ping(self):
|
||||
# method executed every second
|
||||
print("pong")
|
|
@ -0,0 +1,24 @@
|
|||
AMQP_URI: pyamqp://${RABBIT_USER:guest}:${RABBIT_PASSWORD:guest}@${RABBIT_HOST:localhost}:${RABBIT_PORT:5672}/
|
||||
RPC_EXCHANGE: 'nameko-rpc'
|
||||
|
||||
max_workers: 10
|
||||
parent_calls_tracked: 20
|
||||
|
||||
LOGGING:
|
||||
version: 1
|
||||
formatters:
|
||||
tracer:
|
||||
(): nameko_tracer.formatters.PrettyJSONFormatter
|
||||
handlers:
|
||||
tracer:
|
||||
class: logging.StreamHandler
|
||||
formatter: tracer
|
||||
loggers:
|
||||
nameko_tracer:
|
||||
level: INFO
|
||||
handlers: [tracer]
|
||||
|
||||
SENTRY:
|
||||
DSN: ${SENTRY_DSN}
|
||||
CLIENT_CONFIG:
|
||||
site: ${SENTRY_SITE}
|
|
@ -5,14 +5,15 @@ from namekoplus import init_statsd, init_sentry
|
|||
|
||||
|
||||
class EventPublisherService:
|
||||
name = "publisher_service"
|
||||
|
||||
dispatch = EventDispatcher()
|
||||
name = "publisher_service"
|
||||
|
||||
tracer = Tracer()
|
||||
sentry = init_sentry()
|
||||
statsd = init_statsd('statsd_prefix', 'statsd_host', 'statsd_port')
|
||||
|
||||
dispatch = EventDispatcher()
|
||||
|
||||
@rpc
|
||||
@statsd.timer('publish')
|
||||
def publish(self, event_type, payload):
|
||||
|
@ -20,8 +21,10 @@ class EventPublisherService:
|
|||
|
||||
|
||||
class AnEventListenerService:
|
||||
|
||||
name = "an_event_listener_service"
|
||||
|
||||
tracer = Tracer()
|
||||
sentry = init_sentry()
|
||||
statsd = init_statsd('statsd_prefix', 'statsd_host', 'statsd_port')
|
||||
|
||||
|
@ -32,8 +35,10 @@ class AnEventListenerService:
|
|||
|
||||
|
||||
class AnotherEventListenerService:
|
||||
|
||||
name = "another_event_listener_service"
|
||||
|
||||
tracer = Tracer()
|
||||
sentry = init_sentry()
|
||||
statsd = init_statsd('statsd_prefix', 'statsd_host', 'statsd_port')
|
||||
|
||||
|
@ -44,8 +49,10 @@ class AnotherEventListenerService:
|
|||
|
||||
|
||||
class ListenBothEventsService:
|
||||
|
||||
name = "listen_both_events_service"
|
||||
|
||||
tracer = Tracer()
|
||||
sentry = init_sentry()
|
||||
statsd = init_statsd('statsd_prefix', 'statsd_host', 'statsd_port')
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ from namekoplus import init_statsd, init_sentry
|
|||
|
||||
|
||||
class HttpDemoService:
|
||||
|
||||
name = "http_demo_service"
|
||||
|
||||
tracer = Tracer()
|
||||
|
|
|
@ -3,8 +3,9 @@ from nameko_tracer import Tracer
|
|||
from namekoplus import init_statsd, init_sentry
|
||||
|
||||
|
||||
class Service:
|
||||
name = "service"
|
||||
class Timer:
|
||||
|
||||
name = 'timer'
|
||||
|
||||
tracer = Tracer()
|
||||
sentry = init_sentry()
|
||||
|
|
2
setup.py
2
setup.py
|
@ -9,7 +9,7 @@ with open(path.join(here, 'README.md'), encoding='utf-8') as f:
|
|||
|
||||
setup(
|
||||
name='namekoplus',
|
||||
version='0.1.1',
|
||||
version='0.1.2',
|
||||
description='A lightweight Python distributed microservice solution',
|
||||
long_description=long_description,
|
||||
long_description_content_type='text/markdown',
|
||||
|
|
Loading…
Reference in New Issue