Skip to content

cloudevents

Two services agree on a message shape. Six months later there are five services, three of them written by somebody who has left, and the shape is whatever the oldest one happens to emit.

CloudEvents is the agreement written down by somebody else. This module implements it, in binary mode, over the two things every message transport already has: a map of headers, and a body.

h, body, err := cloudevents.Marshal(e)   // map[string][]string, []byte
e, err := cloudevents.Unmarshal(h, body) // and back again

That signature is the whole design. map[string][]string is the underlying type of both nats.Header and http.Header, so this module imports neither, and the same codec works over whichever one you are holding.

A codec, not a protocol binding

This module never opens a connection, subscribes, or publishes. The CloudEvents SDK's bindings do — they own the nats.Conn — which would mean a service sending a CloudEvent bypassed go/nats and lost its bounded subscriptions, shed reporting and lifecycle management. Two modules doing one job with different answers, and the safer one bypassed by the newer one.

Start here

  • Getting started

    An event marshalled, sent over NATS, and read back at the other end.

  • The wire format

    Every header this module writes and reads, and which ones are required.

  • URN grammar

    urn:phpboyscout:schema:orders.created:3, and why identifiers are URNs rather than URLs.

  • Why Unmarshal refuses

    Strictness, what it costs, and the one circumstance that would change the answer.

What it is not

It does not implement structured mode, it does not resolve a dataschema, and it does not know what a transport is. Those are three separate decisions, and each of them is written down.