CloudEvents is a design specification for sending events in a common and uniform way. They are an interesting proposal for standardising the way we send events in an event-driven ecosystem. The specification is an open and a versatile approach for sending and consuming.
Metadata about an event is contained within a CloudEvent, through a number of required (and optional) attributes including:
For more information about the attributes, you can take a look at the cloudevents spec.
Here is an example of a CloudEvent from my previous eventing example:
You can see the required attributes are:
- id: 8e3cf8fb-88bb-4a00-a3fe-0635e221ce92
- source: wss://ws.blockchain.info/inv
- specversion: 0.3
- type: websocket-event
There are also some extension attributes such as knativearrivaltime, knativehistory and traceparent. We then also have the body of the message in Data.
Having these set attributes means they can be used for filtering (e.g through a Knative eventing trigger) and also for capturing key information that can be used by other services that subscribe to the events. I can, for example, filter for events that are only from a certain source or of a certain type.
CloudEvents are currently supported by Knative, Azure Event Grid and Open FaaS.
There are number of libraries for CloudEvents inlcuding for Python, Go and Java. I’ve used the go-sdk for CloudEvents a lot lately and will be running through some of this in some future posts.