sdk-java/docs/index.md

4.9 KiB

title nav_order
Home 1

Java SDK for CloudEvents

A Java API for the CloudEvents specification

  1. Supported Specification Features
  2. Modules
  3. Get Started
  4. Use an event format
  5. Use a protocol binding

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:

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: