Skip to content

Repository files navigation

CDEvents Java SDK

Plumber Score

Java SDK to produce CDEvents.

The SDK can be used to create CDEvents and render as CloudEvents to send them to a specific CloudEvents broker

Add dependency module

<dependency>
<groupId>dev.cdevents</groupId>
<artifactId>cdevents-sdk-java</artifactId>
<version>${cdevents.version}</version>
</dependency>

Create your first CDEvent

Below is the example of creating a new PipelineRun-finished event,

publicclassCDEventsExample {
publicstaticvoidmain(Stringargs[]){
/*when creating new object of any CDEvent type, the event will be initialized with context.id, context.type, context.version, context.timestamp and subject.type */PipelinerunFinishedCDEventpipelinerunFinishedCDEvent = newPipelinerunFinishedCDEvent();
/* set the required context fields to the pipelineRunFinishedCDEvent */pipelinerunFinishedCDEvent.setSource(URI.create("http://dev.cdevents"));
/* set the required subject fields to the pipelineRunFinishedCDEvent */pipelinerunFinishedCDEvent.setSubjectId("/dev/pipeline/run/1");
pipelinerunFinishedCDEvent.setSubjectSource(URI.create("http://dev.pipeline.run/source"));
pipelinerunFinishedCDEvent.setSubjectUrl("http://dev.pipeline.run/url");
pipelinerunFinishedCDEvent.setSubjectOutcome(CDEventConstants.Outcome.SUCCESS.getOutcome());
pipelinerunFinishedCDEvent.setSubjectPipelineName("testPipeline");
pipelinerunFinishedCDEvent.setSubjectErrors("pipelineErrors");
/* Create a CloudEvent from a pipelineRunFinishedCDEvent */CloudEventceEvent = CDEvents.cdEventAsCloudEvent(pipelinerunFinishedCDEvent);
/* This CDEvent can be sent as CloudEvent using HTTP Protocol Binding, Refer : https://cloudevents.github.io/sdk-java/http-basic.html */
}
}

Now the CDEvent can be sent as CloudEvent using Generic HTTP Protocol Binding

Contributing

If you would like to contribute, see our development guide.

References

About

Java SDK for CDEvents

Topics

Resources

Code of conduct

Contributing

Stars

6 stars

Watchers

6 watching

Forks

Releases

Packages

Used by

Contributors

Languages