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-api
Module providing theCloudEvent
and other base interfacescloudevents-core
Module providingCloudEvent
implementation,CloudEventBuilder
to createCloudEvent
s programmatically,EventFormat
to implement Event Formats,Message
/MessageVisitor
to implement Protocol bindingscloudevents-json-jackson
Implementation of JSON Event format with Jacksoncloudevents-http-vertx
Implementation of HTTP Protocol Binding with Vert.x Corecloudevents-http-restful-ws
Implementation of HTTP Protocol Binding for Jakarta Restful WScloudevents-kafka
Implementation of Kafka Protocol Binding
You can look at the latest published artifacts on Maven Central.
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: