Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java SDK for CDE CloudEvents #110

Closed
salaboy opened this issue Feb 4, 2022 · 13 comments
Closed

Java SDK for CDE CloudEvents #110

salaboy opened this issue Feb 4, 2022 · 13 comments

Comments

@salaboy
Copy link
Contributor

salaboy commented Feb 4, 2022

Create an extension for the CloudEvents Java SDK that provides CD Events definitions and types:

https://github.com/cloudevents/sdk-java

This SDK can follow different approaches, by using just the Java SDK or the Spring integration.
We should have basic coverage for events defined in the vocabulary and at least an example app producing and consuming these events.

@rjalander
Copy link
Contributor

@salaboy As discussed over slack, we can discuss the design approach to create Java SDK for cdevents here.

To start with,

  1. I have created spring-boot-restful API end point to consume cloudevents with the sample event data.
  2. Containerized the spring-boot application and deployed in kubernetes kind cluster.
  3. Created a trigger for the consumer API to subscribe with the events-broker and to listen the events of specific type.
  4. Using the curl command, I could send the event to events-broker
    curl -v -d '{"id": "1234", "subject": "event"}' -X POST -H "Ce-Id: say-hello" -H "Ce-Specversion: 1.0" -H "Ce-Type: cd.artifact.packaged.v1" -H "Ce-Source: not-sendoff" -H "Content-Type: application/json" "http://localhost:8090/default/events-broker"
  5. Could able to see the events consumed by Java consume API

Please let me know if we can discuss further on Java SDK for cdevents.

@afrittoli
Copy link
Member

Nice!

I would recommend using https://github.com/cloudevents/sdk-java

Since the SDK will be hosted in the cdevents org, I think we should track this work there. We already have similar issues for python and golang sdks there

@salaboy
Copy link
Contributor Author

salaboy commented Mar 1, 2022

@rjalander as suggested by @afrittoli I would just create a project that depends on https://github.com/cloudevents/sdk-java and define the CD Events classed so we can easily construct CD events

@salaboy
Copy link
Contributor Author

salaboy commented Mar 1, 2022

For example I would like to see that we have the right ENUMs in java to for example define the types in this builder:

final CloudEvent event = CloudEventBuilder.v1()
    .withId("000")
    .withType("example.demo")
    .withSource(URI.create("http://example.com"))
    .withData("text/plain","Hello world!".getBytes())
    .build();

@rjalander
Copy link
Contributor

Thank you for your inputs @afrittoli @salaboy
In the examples I tried, I am using the libraries from https://github.com/cloudevents/sdk-java for client and server.

As per my understanding, now we need to create a java client alone that can emit different types of events (as per cdevents vocabulary) by using the CloudEventBuilder above.
And the same can be viewed on the chosen event broker?
Please correct me If I am wrong.

@rjalander
Copy link
Contributor

rjalander commented Mar 3, 2022

@salaboy I tried constructing the event using CloudEventBuilder and did POST from new java project to event-broker (Launched sockeye locally as event broker), could see the events passed to Sockeye dashboard.

Used cloudevents-core cloudevents-http-basic as dependency modules from cloudevents/sdk-java

CloudEvent event = new CloudEventBuilder()
	            .withId("000")
	            .withSource(URI.create("http://example.com"))
	            .withType("cd.artifact.created.v1")
	            .withData("{ \"id\" : \"1234\" }".getBytes(StandardCharsets.UTF_8))
	            .build();
	URL url = new URL("http://localhost:8090/");
        HttpURLConnection httpUrlConnection = (HttpURLConnection) url.openConnection();
        httpUrlConnection.setRequestMethod("POST");
        
        MessageWriter messageWriter = createMessageWriter(httpUrlConnection);
        messageWriter.writeBinary(event);

If this approach is good, I could parameterize class to send different types of cdevents from CLI?

@salaboy
Copy link
Contributor Author

salaboy commented Mar 12, 2022

@rjalander can you create a PR with the project so I can take a look?
I think that the only CDEvents related thing here are the CE-TYPEs right? This means that what we can do for now is to have the types in constants. This is what we are doing in the Go SDK

https://github.com/cdfoundation/sig-events/blob/main/cde/sdk/go/pkg/cdf/events/event_types.go

Then.. each type of event is defining a set of extensions like this:

https://github.com/cdfoundation/sig-events/blob/main/cde/sdk/go/pkg/cdf/events/event_types.go#L112

I am not sure if this is what the SIG wants to change.. but I would start by having the same as we have in the Go SDK until we make other definitions. @afrittoli if we already have some of those definitions.. can you share them?

To summarize, what I think will be first good steps:

  • Constants with CDEvents types
  • Extensions per type with some helpers.

@afrittoli
Copy link
Member

@rjalander @salaboy I created a new repo for the Java SDK: https://github.com/cdevents/sdk-java

I created a team and invited you both so you can push to the repo. @rjalander you should see an invite to the org as well.

In CDEvents we won't be adding all CDEvents fields in CloudEvents extensions.
We might have extensions for common protocol parts across all events, but we don't have anyone yet.
The v0.1 spec is not complete yet though - and I don't want to stop your progress, so in the meanwhile you could go ahead and follow the approach defined in the draft spec.

@salaboy
Copy link
Contributor Author

salaboy commented Mar 12, 2022

+1

@rjalander
Copy link
Contributor

@salaboy @afrittoli Created a PR with the initial changes - cdevents/sdk-java#1
Please provide your comments.

@afrittoli
Copy link
Member

I created cdevents/spec#46 so we have this issue in the same org as the python and golang ones. If you prefer to keep this open it's ok for me, else I'd would close it in favour of the new one.

@rjalander
Copy link
Contributor

@afrittoli Sure we can close this issue.
Also the PR(cdevents/sdk-java#1) for Java-SDK is already merged, can we close the new issue too, cdevents/spec#46

@e-backmark-ericsson
Copy link
Collaborator

Closing this issue inline with the discussion above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants