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

Add Java Vert.x event bus SockJS bridge example #191

Merged
merged 1 commit into from
May 22, 2017

Conversation

galderz
Copy link
Contributor

@galderz galderz commented May 9, 2017

  • Add Vert.x event bus SockJS bridge example where the client is a Java
    client using Vert.x HTTP client API to receive events over websockets.

As promised :)

* Add Vert.x event bus SockJS bridge example where the client is a Java
  client using Vert.x HTTP client API to receive events over websockets.
@vietj vietj added the to review label May 9, 2017
@tsegismont
Copy link
Contributor

Thank you @galderz ! Can you update the project README to add a section about this example?

@cescoffier cescoffier merged commit 62380c6 into vert-x3:master May 22, 2017
@cescoffier
Copy link
Member

@tsegismont - I've done it.

@galderz it's an awesome example, thanks! Finally, a way to know what time it is from the event bus !

@pmlopes
Copy link
Member

pmlopes commented May 22, 2017

Well a bit too late since this has already been merged, but I'm not sure if this example is a good idea. Not because of the code itself, but because the java client is bypassing the sockjs protocol and nothing is said about it.

It shows how to subscribe to a message but it is not clear/documented or obvious how would you reply to a message. Also it is not clear how you would send a message from the client.

This is not clear because you need to produce a json message in sockjs protocol format. I am afraid that we will get more questions from this example than we help people to connect to the sockjs server.

@cescoffier
Copy link
Member

We can just write in the README and code that it's just to demonstrate it's possible but should not be done like this. the lack of sockJS java client starts to be concerning BTW, for people not willing to use TCP (conveying this low level "semantic").

@pmlopes
Copy link
Member

pmlopes commented May 22, 2017

Actually we could create a simple class that helps with the protocol, something generic, with a couple of static methods e.g.:

interface SockJSMessageBuilder {
  Map send(String to, String from, Map json);
  Map reply(Map json, Map reply);
  Map subscribe(String address);
  Map unsubscribe(String address);
  Map ping();
}

This interface only relies on the JDK itself and only creates the proper messages, so they can be passed to the websocket layer either vert.x or something else...

@vietj
Copy link
Contributor

vietj commented May 22, 2017

we can connect to a SockJS server via websocket using the /websocket URL

@pmlopes
Copy link
Member

pmlopes commented May 22, 2017

@vietj yes but you still need to use the eventbus protocol to send/receive messages. That is my point here.

@vietj
Copy link
Contributor

vietj commented May 22, 2017

where this interface would be ? in the java client for EB ?

@vietj
Copy link
Contributor

vietj commented May 22, 2017

or this interface would be provided by vertx-web and then reused for plain clients ? but it would be duplicate with the java clients

@cescoffier
Copy link
Member

For now, I'm going to revert the merge until we find a better solution.

@galderz
Copy link
Contributor Author

galderz commented May 24, 2017

Well a bit too late since this has already been merged, but I'm not sure if this example is a good idea.

Hmmmm... this is an example implemented out of a practical need I had :|

The use case is defined here, and the repo where I used this code here.

Not because of the code itself, but because the java client is bypassing the sockjs protocol and nothing is said about it.

What do you mean by bypassing?

It shows how to subscribe to a message but it is not clear/documented or obvious how would you reply to a message. Also it is not clear how you would send a message from the client.

There are no replies needed. The client just listens for websocket events since the client is a dashboard. And, the dashboard does not need to communicate with the server.

This is not clear because you need to produce a json message in sockjs protocol format. I am afraid that we will get more questions from this example than we help people to connect to the sockjs server.

What about you help improve the example? I'm no vert.x/sock.js/websocket expert.

Thx

@galderz
Copy link
Contributor Author

galderz commented May 24, 2017

Btw, to reiterate, I'm not the first one I've been trying to do stuff like this... I just pieced stuff together out of replies on Vert.x user group, to be more precise, this post. I don't see anyone complaining ;)

@galderz
Copy link
Contributor Author

galderz commented May 24, 2017

For now, I'm going to revert the merge until we find a better solution.

Unfortunate, I guess we'll have to wait until next user group question appears... 😉

Jokes aside, is the example that bad that needs reverting? Can't you just improve it at all? 🤔

@pmlopes
Copy link
Member

pmlopes commented May 24, 2017

@galderz I'm not against the example, my concern is that the example itself lacked context, now that I see your posts I see the need. Maybe we need to document the use case in the example so the user will not be asking? how do I reply to a message with this? or how do I send a message from the client?

What I was trying to say, either we add a helper class to generate the the Json messages as per the eventbus protocol so all these stuff is hidden and obvious to the user, or we need to provide it from vert.x itself.

And I agree, we should improve it. We just reverted the merge because we want to have a clear example when it goes live with a release.

@pmlopes
Copy link
Member

pmlopes commented May 24, 2017

@galderz I guess if we add some context plus something similar to the interface gist above we can add it and it will be clearer to the user, wdyt?

@galderz
Copy link
Contributor Author

galderz commented May 31, 2017

Maybe we need to document the use case in the example so the user will not be asking?

Sure, that can be added... but in the mean time, while the example is not in this repo, you open yourself to questions like mine or Johannes': how do you connect to SockJS eventbus websocket from Java?

I guess you decide which question your prefer to answer or not to answer :\

how do I reply to a message with this? or how do I send a message from the client?

I don't really know TBH, this is your expertise...

What I was trying to say, either we add a helper class to generate the the Json messages as per the eventbus protocol so all these stuff is hidden and obvious to the user, or we need to provide it from vert.x itself.

I don't really know what the helper should look like. I just got the example to work and that worked for my use case.

I guess if we add some context plus something similar to the interface gist above we can add it and it will be clearer to the user, wdyt?

Inteface? The JavaFX interface presented is very specific to the actual use case, and I don't see any of your examples having fancy interfaces :.

It feels to me you're trying to make this way more complicated than it is.

I don't know what else I can contribute here. This example works for my use case. If the code is not using stuff correctly, you have the expertise to fix it without the need to bring in an interface. The interface will always be specific to a use case, and my use case requires bringing in the data to cycle through, cycling through the data, filter it, push it...etc. Way too much stuff to answer this question:

Is there a way to connect to the SockJS eventbus websocket via java?

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

Successfully merging this pull request may close these issues.

5 participants