The gemstone.event module¶
Event transports¶
- class
gemstone.event.
BaseEventTransport
[source]¶Base class for defining event transports.
The basic workflow would be the following:
- the handlers are registered with the
BaseEventTransport.register_event_handler()
method- the
BaseEventTransport.start_accepting_events()
is invoked- for each incoming event, call
BaseEventTransport.on_event_received()
whose responsibility is to invoke the proper handler function (recommended to use therun_on_main_thread
method)
emit_event
(event_name, event_body)[source]¶Emits an event of type
event_name
with theevent_body
content using the current event transport.
Parameters:
- event_name –
- event_body –
Returns:
on_event_received
(event_name, event_body)[source]¶Handles generic event. This function should treat every event that is received with the designated handler function.
Parameters:
- event_name – the name of the event to be handled
- event_body – the body of the event to be handled
Returns:
register_event_handler
(handler_func, handled_event_name)[source]¶Registers a function to handle all events of type
handled_event_name
Parameters:
- handler_func – the handler function
- handled_event_name – the handled event type
run_on_main_thread
(func, args=None, kwargs=None)[source]¶Runs the
func
callable on the main thread, by using the provided microservice instance’s IOLoop.
Parameters:
- func – callable to run on the main thread
- args – tuple or list with the positional arguments.
- kwargs – dict with the keyword arguments.
Returns:
- class
gemstone.event.
RedisEventTransport
(redis_url)[source]¶Event transport that uses a Redis server as message transport by using the PUBSUB mechanism.
Parameters: redis_url – A string that specifies the network location of the redis server: - redis://[:password@]hostaddr:port/dbnumber
(plaintext) -rediss://[:password@]hostaddr:port/dbnumber
(over TLS) -unix://[:password@]/path/to/socket?db=dbnumber
(Unix socket)
- class
gemstone.event.
RabbitMqEventTransport
(host='127.0.0.1', port=5672, username='', password='', **connection_options)[source]¶Event transport via RabbitMQ server.
Parameters:
- host – ipv4 or hostname
- port – the port where the server listens
- username – username used for authentication
- password – password used for authentication
- connection_options – extra arguments that will be used in
pika.BlockingConnection
initialization.