README.adoc

June 20, 2018 ยท View on GitHub

= Implementation of the CloudEvents Specification

image:https://api.travis-ci.org/project-streamzi/jcloudevents.png[Build Status (Travis CI), link=https://travis-ci.org/project-streamzi/jcloudevents] image:https://img.shields.io/:license-Apache2-blue.svg[License, link=http://www.apache.org/licenses/LICENSE-2.0]

Simple CDI libray for the link:https://github.com/cloudevents/spec[CloudEvents Specification]

A more detailed introduction is link:./introduction.md[here]

Below is a simple overview!

== JAX-RS and Apache Kafka support

Adding the jax-rs or kafka module to your application integrates, either the /ce JAX-RS endpoint, or a configurable Kafka consumer for handling CloudEvents from within your application!

Receiving different multi-cloud events, using the CDI API:

[source,java]

public class Monitor {

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

    System.out.println("S3 event: " + cloudEvent);

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

    System.out.println("Azure event: " + cloudEvent);

}

}

== Java SE / Weld-SE support

Vanilla CDI support and APIs for CloudEvents

=== Creating and firing an event:

[source,java]

public class EventPublisher {

@Inject
private Event<CloudEvent<MyCustomEvent>> cloudEvent;

public void doAndTrigger() throws Exception {

    // do some domain specific stuff...

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

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

}

}

=== Receiving the event

[source,java]

... public void receiveCloudEvent(@Observes @EventType(name = "Cloud.Storage.Item.Created") CloudEvent cloudEvent) {

    receiver.ack();
}