Documentation
¶
Overview ¶
Package event defines the transport-agnostic message envelope exchanged between services. It knows nothing about Kafka: a broker client is responsible for mapping an Event onto whatever its transport calls a topic, a key and a value.
Index ¶
Constants ¶
const TopicOrderCreated = "orders.created"
TopicOrderCreated carries an event per completed purchase order.
Variables ¶
var ErrMalformedEvent = errors.New("malformed event")
ErrMalformedEvent is returned when an Event is missing a required field.
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event struct {
// Topic names the stream this event belongs to. Required.
Topic string `json:"topic"`
// Key determines ordering. Events sharing a key are delivered to consumers
// in publish order; events with different keys have no relative ordering
// guarantee, because a broker is free to place them on separate partitions.
// The key is therefore a domain decision — it declares what must stay
// ordered with respect to what — and is required for that reason.
Key string `json:"key"`
// ID uniquely identifies this event and is the basis for consumer-side
// deduplication. Delivery is at-least-once, so a consumer may see the same
// ID more than once and must treat a repeat as a no-op.
//
// It is generated once, when the event is created, and must survive a
// republish unchanged — an ID minted at publish time would differ on every
// retry and defeat deduplication entirely.
ID string `json:"id"`
// OccurredAt is when the event happened, which is not necessarily when it
// was published or consumed.
OccurredAt time.Time `json:"occurred_at"`
// Data is the domain payload, JSON-encoded on the wire. On a consumed event
// it holds the raw JSON; use DecodeData to unmarshal it into a concrete type.
Data any `json:"data"`
}
Event is a single message.
Topic and Key are routing metadata and are carried by the transport rather than the payload; ID, OccurredAt and Data are the payload and travel together as the encoded value. See Encode for the wire format.
func Decode ¶
Decode reconstructs an Event from a transport's topic, key and value. The resulting Data holds raw JSON — call DecodeData to interpret it.
func (*Event) DecodeData ¶
DecodeData unmarshals the event payload into v.