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

feat: add support for kafka transport #455

Merged
merged 1 commit into from
Jan 7, 2022

Conversation

lance
Copy link
Member

@lance lance commented Dec 22, 2021

This commit extends the message package to include Kafka transport. The tests included here were almost entirely copied verbatim from message_tests.ts which tests the HTTP message binding. The primary change to these tests was the use of the Kafka binding instead of the HTTP binding. It would be nice, I think, to have generic tests that can test any new transport layer by just taking the binding as a parameter. But that's not what I've done here. :) I've mostly just copied and pasted.

There is one test that is pending as it's not passing yet, and I figured it was a bit of an edge case and could be addressed later.

      - Converts base64 encoded data to binary when deserializing structured messages

Note that only JSON encoding is supported.

Additionally, some of the type information has changed across the project to more accurately reflect the type of Message with Message<T>.

Related: #390

@lance lance requested a review from a team December 22, 2021 19:27
@lance lance added module/lib Related to the main source code type/enhancement New feature or request labels Dec 22, 2021
Copy link
Member

@grant grant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few requested changes. Hope the comments are helpful.

Nothing particularly blocking.

I'm not familiar with the goal of the SDKs in terms of supporting all protocols / transports. It be best to keep other transport logic to child helpers since a developer will usually only use the SDK for one protocol at a time.

package-lock.json Show resolved Hide resolved
src/message/index.ts Outdated Show resolved Hide resolved
src/message/index.ts Outdated Show resolved Hide resolved
src/message/kafka/headers.ts Outdated Show resolved Hide resolved
src/message/kafka/index.ts Outdated Show resolved Hide resolved
src/message/kafka/index.ts Outdated Show resolved Hide resolved
src/message/kafka/index.ts Outdated Show resolved Hide resolved
test/integration/emitter_factory_test.ts Outdated Show resolved Hide resolved
test/integration/emitter_singleton_test.ts Outdated Show resolved Hide resolved
@lance
Copy link
Member Author

lance commented Dec 22, 2021

Thanks for the feedback @grant - I've made some updates. Making the generic type T default to string was quite helpful - thanks for pointing that out.

@lance
Copy link
Member Author

lance commented Dec 22, 2021

I'm not familiar with the goal of the SDKs in terms of supporting all protocols / transports. It be best to keep other transport logic to child helpers since a developer will usually only use the SDK for one protocol at a time.

Not sure how I feel about this. Other SDKs do support multiple protocols, and all do so within a single repository. Distributing the bits of these implementations is, of course, language specific. So, in Java, for example, you can pull in just the Kafka bindings iiuc, but that's not the case in Rust, for example, where the implementation is all together. In any case, the different transport protocol support is all implemented in a single github repo - which is what we would need to do as well. I think the additional bytes that are added to the package by these two files are really not an issue compared to the complexity of reorganizing this repo to be a mono-repo, supporting multiple npm modules. My 2c.

@grant
Copy link
Member

grant commented Dec 22, 2021

I'm not familiar with the goal of the SDKs in terms of supporting all protocols / transports. It be best to keep other transport logic to child helpers since a developer will usually only use the SDK for one protocol at a time.

Not sure how I feel about this. Other SDKs do support multiple protocols, and all do so within a single repository. Distributing the bits of these implementations is, of course, language specific. So, in Java, for example, you can pull in just the Kafka bindings iiuc, but that's not the case in Rust, for example, where the implementation is all together. In any case, the different transport protocol support is all implemented in a single github repo - which is what we would need to do as well. I think the additional bytes that are added to the package by these two files are really not an issue compared to the complexity of reorganizing this repo to be a mono-repo, supporting multiple npm modules. My 2c.

Yeah it's fine imo. The main thing is being wary of extra dependencies that may be unnecessary, and ensuring it's still easy to contribute to HTTP features without having to affect other protocols.

Copy link

@LeoVS09 LeoVS09 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for breaking into your working process, but it critical bug was my failure, and it can create complex problems for production applications

src/message/kafka/index.ts Outdated Show resolved Hide resolved
lance added a commit to lance/sdk-javascript that referenced this pull request Jan 4, 2022
This change modifies the protocol binding interfaces such as `Binding`,
`Serializer` and the like to use the `CloudEventV1` interface instead of the
implementation class `CloudEvent`. This should make extending the interfaces
simpler as this work has grown out of efforts around the implementation of
a second transport interface, Kafka.

See: cloudevents#455

This commit also includes the addition of a generic type to the `Message`
interface, defaulting to `string`.

There is also some minor clean up involving what is exported from the
`message/http` modules. Now, instead of exporting the entire implementation,
only the `HTTP` binding implementation is exported, and it is then reexported
by `message`.

Also, a static `CloudEvent.cloneWith()` method has been added which the
instance methods now use.

Signed-off-by: Lance Ball <lball@redhat.com>
lance added a commit to lance/sdk-javascript that referenced this pull request Jan 4, 2022
This change modifies the protocol binding interfaces such as `Binding`,
`Serializer` and the like to use the `CloudEventV1` interface instead of the
implementation class `CloudEvent`. This should make extending the interfaces
simpler as this work has grown out of efforts around the implementation of
a second transport interface, Kafka.

See: cloudevents#455

This commit also includes the addition of a generic type to the `Message`
interface, defaulting to `string`.

There is also some minor clean up involving what is exported from the
`message/http` modules. Now, instead of exporting the entire implementation,
only the `HTTP` binding implementation is exported, and it is then reexported
by `message`.

Also, a static `CloudEvent.cloneWith()` method has been added which the
instance methods now use.

Signed-off-by: Lance Ball <lball@redhat.com>
@lance
Copy link
Member Author

lance commented Jan 4, 2022

@LeoVS09 I've made the appropriate changes, ptal.
@grant @lholmquist a bit has changed sine your last reviews, would you mind taking another look at this? Thanks.

lance added a commit to lance/sdk-javascript that referenced this pull request Jan 4, 2022
This change modifies the protocol binding interfaces such as `Binding`,
`Serializer` and the like to use the `CloudEventV1` interface instead of the
implementation class `CloudEvent`. This should make extending the interfaces
simpler as this work has grown out of efforts around the implementation of
a second transport interface, Kafka.

See: cloudevents#455

This commit also includes the addition of a generic type to the `Message`
interface, defaulting to `string`.

There is also some minor clean up involving what is exported from the
`message/http` modules. Now, instead of exporting the entire implementation,
only the `HTTP` binding implementation is exported, and it is then reexported
by `message`.

Also, a static `CloudEvent.cloneWith()` method has been added which the
instance methods now use.

Signed-off-by: Lance Ball <lball@redhat.com>
lance added a commit to lance/sdk-javascript that referenced this pull request Jan 4, 2022
This change modifies the protocol binding interfaces such as `Binding`,
`Serializer` and the like to use the `CloudEventV1` interface instead of the
implementation class `CloudEvent`. This should make extending the interfaces
simpler as this work has grown out of efforts around the implementation of
a second transport interface, Kafka.

See: cloudevents#455

This commit also includes the addition of a generic type to the `Message`
interface, defaulting to `string`.

There is also some minor clean up involving what is exported from the
`message/http` modules. Now, instead of exporting the entire implementation,
only the `HTTP` binding implementation is exported, and it is then reexported
by `message`.

Also, a static `CloudEvent.cloneWith()` method has been added which the
instance methods now use.

Signed-off-by: Lance Ball <lball@redhat.com>
@lance
Copy link
Member Author

lance commented Jan 5, 2022

Marking as WIP until #457 is resolved as this PR depends on many of those changes, and I think it's better to keep the PRs small and focused vs. cramming all of that in here.

@lance lance marked this pull request as draft January 5, 2022 15:34
lance added a commit that referenced this pull request Jan 7, 2022
* chore(refactor): protocol bindings use interfaces

This change modifies the protocol binding interfaces such as `Binding`,
`Serializer` and the like to use the `CloudEventV1` interface instead of the
implementation class `CloudEvent`. This should make extending the interfaces
simpler as this work has grown out of efforts around the implementation of
a second transport interface, Kafka.

See: #455

This commit also includes the addition of a generic type to the `Message`
interface, defaulting to `string`.

There is also some minor clean up involving what is exported from the
`message/http` modules. Now, instead of exporting the entire implementation,
only the `HTTP` binding implementation is exported, and it is then reexported
by `message`.

Also, a static `CloudEvent.cloneWith()` method has been added which the
instance methods now use.

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: make the `cloneWith()` method is dependent on interfaces

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: remove unnecessary cast

Signed-off-by: Lance Ball <lball@redhat.com>
This commit extends the `message` package to include Kafka transport.

Additionally, some of the type information has changed across the project
to more accurately reflect the type of `Message` (by including `T`).

Related: cloudevents#390
Signed-off-by: Lance Ball <lball@redhat.com>
@lance lance marked this pull request as ready for review January 7, 2022 20:06
@lance
Copy link
Member Author

lance commented Jan 7, 2022

I have rebased with the latest changes from main and generally cleaned this up a bit. It's ready for a final review @grant and/or @lholmquist. Thanks!

@lance lance merged commit 5d1f744 into cloudevents:main Jan 7, 2022
@lance lance deleted the lance/390-add-kafka branch January 7, 2022 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module/lib Related to the main source code type/enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants