EventPublisher

class safir.metrics.EventPublisher(*, manager, event_class, publisher, schema_info)

Bases: Generic[P]

Publishes one type of event.

You shouldn’t need to instantiate instances of this class yourself, they should be instantiated by an EventManager. This is a bucket to remember attributes and type information about one kind of event at initialization time, to later be used at publishing time in a type-safe way.

Parameters:
  • manager (EventManager) – The EventManager that will actually publish the event to Kafka

  • event_class (type[AvroBaseModel]) – An AvroBaseModel with the fields from the payload P, EventMetadata, and an inner Meta class with schema info

  • publisher (AsyncAPIDefaultPublisher) – A FastStream publisher to publish the event to Kafka. This contains Kafka metadata, like the topic to publish to.

  • schema_info (SchemaInfo)

Methods Summary

publish(payload)

Pass the payload and event info to the EventManager to publish.

Methods Documentation

async publish(payload)

Pass the payload and event info to the EventManager to publish.

Parameters:
  • Payload – A subclass of EventPayload to be enriched with metadata and published to Kafka.

  • payload (TypeVar(P, bound= EventPayload))

Returns:

The full, enriched-with-metadata, event model that was published.

Return type:

dataclasses_avroschema.pydantic.AvroBaseModel