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

Websocket protocol binding (only client) #606

Merged
merged 3 commits into from
Nov 24, 2020

Conversation

slinkydeveloper
Copy link
Member

@slinkydeveloper slinkydeveloper commented Nov 9, 2020

Part of #598

  • Implemented websocket protocol binding, only client-side (server-side in a followup)
  • Added a sample
  • Added a new utils package to encapsulate some common messages (Later we can refactor some nats code to use that, deduplicating code)
  • Fixed docs of protocol/inbound.go

Signed-off-by: Francesco Guardiani [email protected]

Signed-off-by: Francesco Guardiani <[email protected]>
Cleanup some stuff

Signed-off-by: Francesco Guardiani <[email protected]>
@slinkydeveloper slinkydeveloper changed the title [WIP] Websocket protocol binding (only client) Websocket protocol binding (only client) Nov 10, 2020

// UnsafeReceive is like Receive, except it doesn't guard from multiple invocations
// from different goroutines.
func (c *ClientProtocol) UnsafeReceive(ctx context.Context) (binding.Message, error) {
Copy link
Member

Choose a reason for hiding this comment

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

might not export this, seems like a footgun

Copy link
Member Author

@slinkydeveloper slinkydeveloper Nov 10, 2020

Choose a reason for hiding this comment

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

It's not a footgun, on the contrary this is expected for a websocket user to be unable to invoke multiple times from different goroutines a method to read from the same connection, because she/he knows the wasm stream is not multiplexed. I wish to keep it pub for "power users" of websockets that doesn't want this (huge) lock in front

Copy link
Member Author

Choose a reason for hiding this comment

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

If you feel this is really problematic, we can make it unexported and export it later


func consumeStream(reader io.Reader) {
//TODO is there a less expensive way to consume the stream?
ioutil.ReadAll(reader)
Copy link
Member

Choose a reason for hiding this comment

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

There might be some fancy seek thing we can do later... so we try to find the edge of a single event at a time

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't need to find the edge of the websocket message, this is already done by the lib itself. But yeah this is open to optimizations

@n3wscott
Copy link
Member

LGTM

I want to see the server side now :D

@@ -9,6 +9,7 @@ import (
// Receiver receives messages.
type Receiver interface {
// Receive blocks till a message is received or ctx expires.
// Receive can be invoked safely from different goroutines.

Choose a reason for hiding this comment

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

I think this is a very big implication here, meaning that all the receive function in all protocol need to be checked to see if this is true.

Copy link
Member Author

Choose a reason for hiding this comment

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

They already are, otherwise they couldn't pass the integration tests 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

This missing comment was more a mistake than a "new feature"

protocol/ws/v2/subprotocols_test.go Outdated Show resolved Hide resolved

var SupportedSubprotocols = []string{JsonSubprotocol}

func resolveFormat(subprotocol string) (format.Format, websocket.MessageType, error) {

Choose a reason for hiding this comment

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

The format has already supported different format types, are you planing to support different types? I am wondering if we can leverage or improve the existing framework.

if f := formats[mediaType]; f != nil {

Copy link
Member Author

Choose a reason for hiding this comment

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

In sdk-go we support only the EventFormat atm, so here i'm just mapping to what we support currently

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah I see your point now, well this "mapping" of subprotocols is very specific to websockets protocol binding https://github.com/cloudevents/spec/blob/master/websockets-protocol-binding.md#15-cloudevents-subprotocols, i guess this code should live only in the websockets protocol. Also because it uses a websocket type (websocket.MessageType)

Signed-off-by: Francesco Guardiani <[email protected]>
Copy link
Member

@n3wscott n3wscott left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@slinkydeveloper slinkydeveloper merged commit 44f150f into cloudevents:master Nov 24, 2020
@slinkydeveloper slinkydeveloper deleted the issues/598 branch November 24, 2020 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/protocol enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants