Nameko dependency provider that dispatches log data using Events (Pub-Sub).
Project description
Nameko dependency provider that dispatches log data using Events (Pub-Sub).
Usage
Dispatching event log data
Include the EventLogDispatcher dependency in your service class:
from nameko.rpc import rpc
from nameko_eventlog_dispatcher import EventLogDispatcher
class FooService:
name = 'foo'
eventlog_dispatcher = EventLogDispatcher()
@rpc
def foo_method(self):
self.eventlog_dispatcher('foo_event_type', {'value': 1})
event_type and some event_data (optional) will be provided as arguments. event_data must contain JSON serializable data.
Calling foo_method will dispatch an event from the foo service with log_event as the event type.
Then, any nameko service will be able to handle this event.
from nameko.events import event_handler
class BarService:
name = 'bar'
@event_handler('foo', 'log_event')
def foo_log_event_handler(self, body):
"""`body` will contain the event log data."""
Capturing log data when entrypoints are fired
Enable auto capture event logs in your nameko configuration file:
# config.yaml
EVENTLOG_DISPATCHER:
auto_capture: true
entrypoints_to_exclude: []
With auto_capture set to true, a nameko event will be dispatched every time an entrypoint is fired:
The source service for these events will be all.
The event type will be entrypoint_fired.
Only entrypoints listed in the ENTRYPOINT_TYPES_TO_LOG class attribute will be logged.
entrypoints_to_exclude can be used to provide a list of entrypoint method names to exclude when firing events automatically.
Then, any nameko service will be able to handle this kind of events:
from nameko.events import event_handler
class BazService:
name = 'baz'
@event_handler('all', 'entrypoint_fired')
def all_entrypoint_fired_event_handler(self, body):
"""Body will contain the event log data."""
Format of the event log data
This is the format of the event log data:
{
"entrypoint_name": "foo_method",
"service_name": "foo",
"timestamp": "2017-06-12T13:48:16+00:00",
"event_type": "foo_event_type",
"data": {},
"call_stack": [
"standalone_rpc_proxy.call.3f349ea4-ed3e-4a3b-93d0-a36fbf928ecb",
"bla.bla_method.21d623b4-edc4-4232-9957-4fad72533b75",
"foo.foo_method.d7e907ee-9425-48a6-84e6-89db19e3ce50"
],
"entrypoint_protocol": "Rpc",
"call_id": "foo.foo_method.d7e907ee-9425-48a6-84e6-89db19e3ce50"
}
The data attribute will contain the event data that was provided as an argument for the event_data parameter when dispatching the event.
Tests
It is assumed that RabbitMQ is up and running on the default URL guest:guest@localhost and uses the default ports.
$ make test
$ make coverage
A different RabbitMQ URI can be provided overriding the following environment variables: RABBIT_CTL_URI and AMQP_URI.
Additional pytest parameters can be also provided using the ARGS variable.
$ make test RABBIT_CTL_URI=http://guest:guest@dockermachine:15673 AMQP_URI=amqp://guest:guest@dockermachine:5673 ARGS='-x -vv --disable-pytest-warnings'
$ make coverage RABBIT_CTL_URI=http://guest:guest@dockermachine:15673 AMQP_URI=amqp://guest:guest@dockermachine:5673 ARGS='-x -vv --disable-pytest-warnings'
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for nameko-eventlog-dispatcher-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d63c2204759373badaeefdac3a6ec9630a0dc4bbd9811d617258562ed30f3ce |
|
MD5 | a463f9f64c7d9ba0ac98d2575e66ee0d |
|
BLAKE2b-256 | 2c2eebed0f415f3d9345a1241647fe18ee6168406318641b1356aed045e976ef |
Hashes for nameko_eventlog_dispatcher-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b64ed4d291d93fdb0e7377fb0f4589a90b40fd3341a9ab75968683989cc62269 |
|
MD5 | 40c48e6b889bceaf0e6b5e43f35b0b36 |
|
BLAKE2b-256 | 9b3d784f9673fd178597db572f24c7045115d0553e66d23cd5b3dc5da6289ca8 |