publisher

The publisher module provides the Publisher class to publish messages to RabbitMQ

class Publisher(rabbitmq_config, base_routing_key=u'')[source]

Bases: object

Publisher encapsulates the logic for async publishing to RabbitMQ

Parameters:
  • rabbitmq_config (pyloggr.config.RabbitMQBaseConfig) – RabbitMQ connection parameters
  • base_routing_key (str) – This routing key will be used if no routing_key is provided to publish methods
publish(exchange, body, routing_key='', message_id=None, headers=None, content_type="application/json", content_encoding="utf-8", persistent=True, application_id=None, event_type=None)[source]

Publish a message to RabbitMQ

Parameters:
  • exchange (str) – publish to this exchange
  • body (str) – message body
  • routing_key (str) – optional routing key
  • message_id (str) – optional ID for the message
  • headers (dict) – optional message headers
  • content_type (str) – message content type
  • content_encoding (str) – message charset
  • persistent (bool) – if True, message will be persisted in RabbitMQ
  • application_id (str) – optional application ID
  • event_type (str) – optional message type

:param : :type : rtype: bool

Note

Coroutine

publish_event(event, routing_key=u'', exchange=u'', application_id=u'', event_type=u'')[source]

Publish an Event object in RabbitMQ. Always persistent.

Parameters:
  • event (pyloggr.event.Event) – Event object
  • routing_key (str or unicode) – RabbitMQ routing key
  • exchange (str or unicode) – optional exchange (override global config)
  • application_id (str or unicode) – optional application ID (override global config)
  • event_type (str or unicode) – optional event type (override global config)

Note

Tornado coroutine

start()[source]

Starts the publisher.

start() raises RabbitMQConnectionError if no connection can be established. If connection succeeds, it returns a toro.Event object that will resolve when connection will be lost

Note

Coroutine

stop()[source]

Stops the publisher

Note

Tornado coroutine