https://github.com/cdevents/sdk-java
Java SDK for CDEvents
https://github.com/cdevents/sdk-java
cdevents hacktoberfest java sdk
Last synced: 5 months ago
JSON representation
Java SDK for CDEvents
- Host: GitHub
- URL: https://github.com/cdevents/sdk-java
- Owner: cdevents
- License: apache-2.0
- Created: 2022-03-12T09:40:23.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-03-12T21:54:19.000Z (over 2 years ago)
- Last Synced: 2024-03-12T22:46:13.900Z (over 2 years ago)
- Topics: cdevents, hacktoberfest, java, sdk
- Language: Java
- Homepage:
- Size: 333 KB
- Stars: 4
- Watchers: 5
- Forks: 6
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CDEvents Java SDK
Java SDK to produce [CDEvents](https://cdevents.dev).
The SDK can be used to create CDEvents and render as CloudEvents to send them to a specific CloudEvents broker
## Add dependency module
```xml
dev.cdevents
cdevents-sdk-java
${cdevents.version}
```
## Create your first CDEvent
Below is the example of creating a new [PipelineRun-finished](https://cdevents.dev/docs/core/#pipelinerun-finished) event,
```java
public class CDEventsExample {
public static void main(String args[]){
/*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 */
PipelinerunFinishedCDEvent pipelinerunFinishedCDEvent = new PipelinerunFinishedCDEvent();
/* 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 */
CloudEvent ceEvent = 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](https://cloudevents.github.io/sdk-java/http-basic.html)
## Contributing
If you would like to contribute, see our [development](DEVELOPMENT.md) guide.
## References
- [CDEvents](https://cdevents.dev)
- [CDEvents Primer](https://cdevents.dev/docs/primer/)
- [CDFoundation Specification](https://cdevents.dev/docs/)