4.9 KiB
| title | nav_order |
|---|---|
| Home | 1 |
Java SDK for CloudEvents
A Java API for the CloudEvents specification
Supported Specification Features
Supported features of the specification:
| v0.3 | v1.0 | |
|---|---|---|
| CloudEvents Core | ✔️ | ✔️ |
| AMQP Protocol Binding | ❌ | ❌ |
| AVRO Event Format | ❌ | ❌ |
| HTTP Protocol Binding | ✔️ | ✔️ |
| - Vert.x | ✔️ | ✔️ |
| - Jakarta Restful WS | ✔️ | ✔️ |
| JSON Event Format | ✔️ | ✔️ |
| - Jackson | ✔️ | ✔️ |
| Kafka Protocol Binding | ✔️ | ✔️ |
| MQTT Protocol Binding | ❌ | ❌ |
| NATS Protocol Binding | ❌ | ❌ |
| Web hook | ❌ | ❌ |
Modules
The CloudEvents SDK for Java is composed by several modules, each one providing a different feature from the different sub specs of CloudEvents specification:
cloudevents-apiModule providing theCloudEventand other base interfacescloudevents-coreModule providingCloudEventimplementation,CloudEventBuilderto createCloudEvents programmatically,EventFormatto implement Event Formats,Message/MessageVisitorto implement Protocol bindingscloudevents-json-jacksonImplementation of JSON Event format with Jacksoncloudevents-http-vertxImplementation of HTTP Protocol Binding with Vert.x Corecloudevents-http-restful-wsImplementation of HTTP Protocol Binding for Jakarta Restful WScloudevents-kafkaImplementation of Kafka Protocol Binding
The latest SDK version is 2.0.0-milestone1.
Get Started
You can start creating events using the CloudEventBuilder:
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();
Look at cloudevents-core README for more information.
Use an event format
Event formats implementations are auto-discovered through an SPI. You can use them accessing through EventFormatProvider.
For example, given you have in your classpath the cloudevents-json-jackson module, you can serialize/deserialize an event to/from JSON using:
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);
Use a protocol binding
Each protocol binding has its own APIs, depending on the library/framework it's integrating with. Check out the documentation of the protocol binding modules: