-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Conversation
* 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.
Thank you @galderz ! Can you update the project README to add a section about this example? |
@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 ! |
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. |
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"). |
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... |
we can connect to a SockJS server via websocket using the |
@vietj yes but you still need to use the eventbus protocol to send/receive messages. That is my point here. |
where this interface would be ? in the java client for EB ? |
or this interface would be provided by vertx-web and then reused for plain clients ? but it would be duplicate with the java clients |
For now, I'm going to revert the merge until we find a better solution. |
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.
What do you mean by bypassing?
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.
What about you help improve the example? I'm no vert.x/sock.js/websocket expert. Thx |
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 ;) |
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? 🤔 |
@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. |
@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? |
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 :\
I don't really know TBH, this is your expertise...
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.
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:
|
client using Vert.x HTTP client API to receive events over websockets.
As promised :)