The base classes, interfaces and low-level APIs to use CloudEvents.
import io.cloudevents.CloudEvent;
import io.cloudevents.core.builder.CloudEventBuilder;
import java.net.URI;
final CloudEvent event = CloudEventBuilder.v1()
.withId("000")
.withType("example.demo")
.withSource(URI.create("http://example.com"))
.withData("application/json", "{}".getBytes())
.build();CloudEvent extensions can be materialized in their respective POJOs:
import io.cloudevents.core.extensions.DistributedTracingExtension;
import io.cloudevents.core.extensions.ExtensionsParser;
DistributedTracingExtension dte = ExtensionsParser.getInstance()
.parseExtension(DistributedTracingExtension.class, event);The SDK implements Event Formats in submodules.
To use them, you just need to add them as dependencies to your project and the SDK,
through the ServiceLoader mechanism, will load them into the classpath.
For example, to use the JSON event format with Jackson,
add cloudevents-json-jackson as a dependency and then:
import io.cloudevents.core.format.EventFormatProvider;
import io.cloudevents.jackson.JsonFormat;
EventFormat format = EventFormatProvider
.getInstance()
.resolveFormat(JsonFormat.CONTENT_TYPE);
// Serialize event
byte[] serialized = format.serialize(event);
// Deserialize event
CloudEvent event = format.deserialize(bytes);