-
Notifications
You must be signed in to change notification settings - Fork 160
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
Rework the Event interface #108
Rework the Event interface #108
Conversation
Signed-off-by: Francesco Guardiani <[email protected]>
/lgtm |
Although the languages are really different, I want to point how the structure is designed in sdk-rust: |
@slinkydeveloper remember to signoff the commits |
I would like to propose to remove any external dep, like Jackson and Bean Validations. With that, CloudEvents API will work with any framework without issues. It will be nice if we have an API module with just the definitions, them a JSON module with Jackson serialization, KAFKA, AVRO, protobuf, http and so on... You know what I mean, modules for Event Formats and modules for Transport Binding. When someone wants to use the API, add just this dependency. If they want JSON, they add the json-jackson module, if they want http they add http-vertx module and son on... |
@slinkydeveloper is really hard to create the same structure in every SDK. |
Go ahead! it's looking nice! |
Ok I'll continue down that road, but be aware that this means reworking most of the sdk. Plus I'm going to drop 0.2, because of its weird extension things (and because according to this document we don't need it https://github.com/cloudevents/spec/blob/master/SDK.md#contribution-acceptance |
@fabiojose since those changes are radical, i think we need a v2 version of the sdk for this. Do you agree on branching the current master creating a 1.x branch? |
Signed-off-by: Francesco Guardiani <[email protected]>
…uages like Java has method overloading Signed-off-by: Francesco Guardiani <[email protected]>
Signed-off-by: Francesco Guardiani <[email protected]>
Signed-off-by: Francesco Guardiani <[email protected]>
*/ | ||
public interface CloudEvent<A extends Attributes, T> { | ||
public interface CloudEvent { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes this is a good change. too many generics makes this really hard to use.
@@ -133,9 +133,9 @@ private BinaryUnmarshaller() {} | |||
*/ | |||
HeadersStep<A, T, P> builder(EventBuilder<T, A> builder); | |||
} | |||
|
|||
|
|||
private static final class Builder<A extends Attributes, T, P> implements |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this still has the layer cake of generics
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still needs to be removed 😄
|
||
import java.io.IOException; | ||
|
||
public class CloudEventSerializer extends StdSerializer<CloudEvent> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice. nice nice.
module.addSerializer(ZonedDateTime.class, new ZonedDateTimeSerializer()); | ||
module.addDeserializer(ZonedDateTime.class, new ZonedDateTimeDeserializer()); | ||
MAPPER.registerModule(module); | ||
} | ||
|
||
protected static final DateTimeFormatter RFC3339_DATE_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for what it's worth, the go sdk uses the RFC3339 Nano format... but they both work together.
module.addSerializer(ZonedDateTime.class, new ZonedDateTimeSerializer()); | ||
module.addDeserializer(ZonedDateTime.class, new ZonedDateTimeDeserializer()); | ||
MAPPER.registerModule(module); | ||
} | ||
|
||
protected static final DateTimeFormatter RFC3339_DATE_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX"); | ||
|
||
public static String encode(final CloudEvent event) throws IllegalStateException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
encode == structured mode?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So these are marshal/unmarshal methods for Cloudevent to go back and forth to JsonValue/String encoded json/binary encoded json
Here is my little demo of using the current java sdk in a spring app and it was quite painful: I would love to see the amount of work I need to do be reduced. This PR is starting in that direction, Thanks @slinkydeveloper !! |
Signed-off-by: Francesco Guardiani <[email protected]>
api/src/main/java/io/cloudevents/extensions/DistributedTracingExtension.java
Outdated
Show resolved
Hide resolved
api/src/main/java/io/cloudevents/extensions/DistributedTracingExtension.java
Outdated
Show resolved
Hide resolved
public final class ExtensionsParser { | ||
|
||
private static class SingletonContainer { | ||
private final static ExtensionsParser INSTANCE = new ExtensionsParser(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ExtensionsParser
as enum
with a single INSTANCE
value would work as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH I prefer this way, the singletons with enums sounds too weird to me 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually... is it possible to avoid singletons for extensions by passing an extension parser to the event parser
It would be nice to be able to provide non-static extension parsers (e.g. by injecting with some DI framework)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think as a first pass is fine, we'll improve this part later. For now i just made the bare minimum to make it working, since it's my priority 😄.
Signed-off-by: Francesco Guardiani <[email protected]>
Signed-off-by: Francesco Guardiani <[email protected]>
Signed-off-by: Francesco Guardiani <[email protected]>
Signed-off-by: Francesco Guardiani <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FTR Although I really appreciate @slinkydeveloper's work on this, and there are some great things in it, I think this PR is too big to be accepted.
- There wasn't enough (public?) discussions on issues like this one: Modularization: api module #111
- It clearly can be separated into a few smaller PRs (e.g. Remove
Attributes
interface #118) - Some decisions IMO require more discussions, and not as PR comments, but as separate issues (e.g. the use of
Optional
).
As was stated, it is planned to create 2.x
version of the SDK, and it is a great chance to rethink and fix the issues of 1.x
. A massive PR is not the best approach to handle it if you ask me :)
I have a more general question. Why do we need to make At it's current state
Why. . .? We certainly don't wan to get into arguments such as ". . .this marshaller is more performant than that,. . . Gson vs Jackson etc. . ., " |
@olegz FYI this PR seems to remove the dependencies from -api: |
This discussion started the 27 Feb 2020 in sdk meetings (https://docs.google.com/document/d/1JIZxnV_w-dMrSAguG4bqog1vBlD94mm5aFjJlfb-R34/edit?usp=sharing) but nobody had counter-arguments again a big refactor of the sdk through a pr like this. As I said, I don't like proceeding this way and I'm ready to engage further discussions (like It's not perfect: on the contrary it needs a lot of work and there are no definitive decisions, but we need to start somewhere. Follow-up PRs will improve the work done here and, i underline, i'm really happy to engage the community to discuss these and future improvements. |
I'm going to also open a Github project with things we want to have, to discuss and to improve for sdk v2 |
I am sure there were some discussions, but it would be better if they were more asynchronous (e.g. on GitHub issues) because not everyone can join the call and have the answers ready :)
I hope my comments did not sound attacking - that's a great change and I am glad to see it happening! Just wanted to mention (as a feedback) that, as an external collaborator, I find the way the SDK gets such changes a bit closed group-ed.
That's a great idea! It will definitely help the visibility of both the current and upcoming states 👍 |
Signed-off-by: Francesco Guardiani <[email protected]>
Json roundtrip works Added extensions to tests Signed-off-by: Francesco Guardiani <[email protected]>
I removed the WIP flag, for me this PR is ready to merge. |
Signed-off-by: Francesco Guardiani <[email protected]>
LGTM |
Hi,
I wish to propose a rework of the
Event
interface and related. I've tried to use this sdk in a middleware experiment (https://github.com/slinkydeveloper/cloud-streaming-data-plane) and I've found several issues with the actualEvent
interface.I think the problems from a middleware point of view are:
While from an "end user" perspective (who reads and writes events from json or from http):
data
field, I don't want to handle the difference between base64 and json serialized. I just want to get thedata
in the way I want (as json or as binary array)From the experience of working on sdk-go and sdk-rust I've tried to bake a modified
Event
interface, let me know your thoughts.Signed-off-by: Francesco Guardiani [email protected]