Skip to content
This repository has been archived by the owner on Nov 13, 2019. It is now read-only.

Latest commit

 

History

History
57 lines (39 loc) · 2.76 KB

introduction.md

File metadata and controls

57 lines (39 loc) · 2.76 KB

CloudEvents with Jakarta EE and the Eclipse Microprofile

The CloudEvent specification is 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.1 and it describes a simple event format, which was demonstrated at last KubeCon 2018 using different Serverless platforms, such as Apache Openwhisk.

Java API

Based on the specification we started to look at an early implementation of the API for Java and CDI. Using the API your backend application can create typed CloudEvents, such as:

CloudEvent<MyCustomEvent> event = new CloudEventBuilder<MyCustomEvent>()
    .eventType("My.Cloud.Storage.Item.Created")
    .source(new URI("/trigger"))
    .eventID(UUID.randomUUID().toString())
    .build();

In Enterprise Java applications, implemented with Jakarta EE or the Eclipse Microprofile, it's trivial to combine this API with CDI. Application developers can now fire a CloudEvent for further processing inside of the application:

cloudEvent.select(
    new EventTypeQualifier("My.Cloud.Storage.Item.Created"))
.fire(event);

This will basically route the event to an Observer Bean, that is interested in the specific event type:

public void receiveCloudEvent(
  @Observes @EventType(name = "My.Cloud.Storage.Item.Created") CloudEvent cloudEvent) {
  // handle the event
}                                                                                       

JAX-RS Bridge

The library contains a JAX-RS endpoint that is able to receive CloudEvent payloads, and fires a CDI event, so that an application just needs to define their listeners like:

public class MultiCloudMonitor {

    public void receiveCloudEventFromAWS(@Observes @EventType(name = "aws.s3.object.created") CloudEvent<?> cloudEvent) {

        // process the AWS event...
    }
    public void receiveCloudEventFromAzure(@Observes @EventType(name = "Microsoft.Storage.BlobCreated") CloudEvent<?> cloudEvent) {

        // process the Azure event...
    }
}

This allows developers to register their Microprofile or JakartaEE application for consumption of events, triggered by different cloud providers!

Outlook

The new reactive messaging specification from the the Eclipse Microprofile initiative will model its own eventing metadata after the CloudEvent specification as an abstraction mechanism for events and their actual transports!