Skip to main content

EventDispatcher

Dispatches event messages.

Attributes

AttributeTypeDescription
DISABLED_TRANSPORTSset = {'sql'}A set of transport driver types for which event dispatching is automatically disabled.
app[Celery](../../app/base/celery.md?sid=celery_app_base_celery) = NoneThe Celery application instance associated with this dispatcher.
on_enabledset = Noneset of callbacks to be called when :meth:enabled.
on_disabledset = Noneset of callbacks to be called when :meth:disabled.
publisherkombu.ProducerAlias for the internal producer instance used to publish messages to the broker.

Constructor

Signature

def EventDispatcher(
connection: kombu.Connection = None,
hostname: str = None,
enabled: bool = True,
channel: kombu.Channel = None,
buffer_while_offline: bool = True,
app: [Celery](../../app/base/celery.md?sid=celery_app_base_celery) = None,
serializer: str = None,
groups: Sequence[str] = None,
delivery_mode: int = 1,
buffer_group: frozenset = None,
buffer_limit: int = 24,
on_send_buffered: Callable = None
)

Parameters

NameTypeDescription
connectionkombu.Connection = NoneConnection to the broker.
hostnamestr = NoneHostname to identify the dispatcher.
enabledbool = TrueWhether to actually publish events.
channelkombu.Channel = NoneSpecific channel to use for sending events.
buffer_while_offlinebool = TrueIf true, events are buffered while the connection is down.
app[Celery](../../app/base/celery.md?sid=celery_app_base_celery) = NoneThe Celery app instance.
serializerstr = NoneThe serialization method to use.
groupsSequence[str] = NoneList of event groups to send.
delivery_modeint = 1Transient (1) or Persistent (2) delivery.
buffer_groupfrozenset = NoneGroups that should be buffered.
buffer_limitint = 24Maximum number of events in a group buffer before flushing.
on_send_bufferedCallable = NoneCallback for when an event is buffered.

Methods


enable()

@classmethod
def enable()

Initializes the message producer and triggers all registered on_enabled callbacks.


disable()

@classmethod
def disable()

Deactivates the dispatcher, closes the producer, and triggers all registered on_disabled callbacks.


publish()

@classmethod
def publish(
type: str,
fields: dict,
producer: kombu.Producer,
blind: bool,
Event: Callable
) - > Any

Publish event using custom :class:~kombu.Producer.

Parameters

NameTypeDescription
typestrEvent type name, with group separated by dash (-).
fieldsdictDictionary of event fields, must be json serializable.
producerkombu.ProducerProducer instance to use: only the publish method will be called.
blindboolDon't set logical clock value (also don't forward the internal logical clock).
EventCallableEvent type used to create event. Defaults to :func:Event.

Returns

TypeDescription
AnyThe result of the internal _publish call.

send()

@classmethod
def send(
type: str,
blind: bool,
utcoffset: Callable,
retry: bool,
retry_policy: dict,
Event: Callable,
**fields: Any
) - > Any

Send event.

Parameters

NameTypeDescription
typestrEvent type name, with group separated by dash (-).
blindboolDon't set logical clock value (also don't forward the internal logical clock).
utcoffsetCallableFunction returning the current utc offset in hours.
retryboolRetry in the event of connection failure.
retry_policydictMap of custom retry policy options.
EventCallableEvent type used to create event, defaults to :func:Event.
**fieldsAnyEvent fields -- must be json serializable.

Returns

TypeDescription
AnyReturns the result of the publication or None if the event is buffered or ignored.

flush()

@classmethod
def flush(
errors: bool,
groups: bool
)

Flush the outbound buffer.

Parameters

NameTypeDescription
errorsboolIf true, attempts to send events that were buffered due to previous connection errors.
groupsboolIf true, flushes events that were intentionally buffered by group.

extend_buffer()

@classmethod
def extend_buffer(
other: [EventDispatcher](eventdispatcher.md?sid=celery_events_dispatcher_eventdispatcher)
)

Copy the outbound buffer of another instance.

Parameters

NameTypeDescription
other[EventDispatcher](eventdispatcher.md?sid=celery_events_dispatcher_eventdispatcher)The other dispatcher instance from which to copy buffered events.

close()

@classmethod
def close()

Close the event dispatcher.