A Java API for the CloudEvents specification
Checkout the changelog
This SDK current supports the following versions of CloudEvents:
- v1.0
The CloudEvents specification is a vendor-neutral specification for defining the format of event data that is being exchanged between different cloud systems. The specification basically defines an abstract envelope for any event data payload, without knowing specific implementation details of the actual underlying event. The current version of the spec is at 0.3
and it describes a simple event format, which was demonstrated at KubeCon 2018 using different Serverless platforms, such as Apache Openwhisk.
For Maven based projects, use the following to configure the CloudEvents Java SDK:
<dependency>
<groupId>io.cloudevents</groupId>
<artifactId>cloudevents-api</artifactId>
<version>1.3.0</version>
</dependency>
Application developers can now create strongly-typed CloudEvents, such as:
import io.cloudevents.v1.CloudEventBuilder;
import io.cloudevents.v1.CloudEventImpl;
import io.cloudevents.extensions.ExtensionFormat;
import io.cloudevents.json.Json;
import io.cloudevents.extensions.DistributedTracingExtension;
// given
final String eventId = UUID.randomUUID().toString();
final URI src = URI.create("/trigger");
final String eventType = "My.Cloud.Event.Type";
final MyCustomEvent payload = ...
// add trace extension usin the in-memory format
final DistributedTracingExtension dt = new DistributedTracingExtension();
dt.setTraceparent("00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01");
dt.setTracestate("rojo=00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01");
final ExtensionFormat tracing = new DistributedTracingExtension.Format(dt);
// passing in the given attributes
final CloudEventImpl<MyCustomEvent> cloudEvent =
CloudEventBuilder.<MyCustomEvent>builder()
.withType(eventType)
.withId(eventId)
.withSource(src)
.withData(payload)
.withExtension(tracing)
.build();
// marshalling as json
final String json = Json.encode(cloudEvent);
Or, an event with binary event data:
import io.cloudevents.v1.CloudEventBuilder;
import io.cloudevents.v1.CloudEventImpl;
import io.cloudevents.extensions.ExtensionFormat;
import io.cloudevents.json.Json;
import io.cloudevents.extensions.DistributedTracingExtension;
// given
final String eventId = UUID.randomUUID().toString();
final URI src = URI.create("/trigger");
final String eventType = "My.Cloud.Event.Type";
final byte[] payload = "a-binary-event-data".getBytes();
// passing in the given attributes
final CloudEventImpl<String> cloudEvent =
CloudEventBuilder.<String>builder()
.withType(eventType)
.withId(eventId)
.withSource(src)
.withDataBase64(payload)
.build();
// marshalling as json that will have the data_base64
final String json = Json.encode(cloudEvent);
There are other detailed ways of how to use the marshallers and unmarshallers with HTTP transport binding.
The support for kafka protocol binding is available. Read the documentation and examples of use.
The API is kept simple, for allowing a wide range of possible integrations:
- There are bi-weekly calls immediately following the Serverless/CloudEvents call at 9am PT (US Pacific). Which means they will typically start at 10am PT, but if the other call ends early then the SDK call will start early as well. See the CloudEvents meeting minutes to determine which week will have the call.
- Slack: #cloudeventssdk channel under CNCF's Slack workspace.
- Email: https://lists.cncf.io/g/cncf-cloudevents-sdk
- Contact for additional information: Fabio José (
@fabiojose
on slack).