-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
WebSockets Next: client endpoints #40309
Conversation
I started working with this and I am probably missing a lot in the way this is meant to be used, but I am really struggling to figure out what the declarative client gives me over being able to define message handlers on |
Well, for simle stuff a message handler represented as a callback works well. But for things like automatic serizalization/deserialization, CDI context activation, I can imagine that we support the simple callbacks as well. But TBH if you want to use callbacks then just use |
Not true really because that gets me into callback hell :) |
In the client? Is that really useful? |
FYI I've added the @Singleton
public class Service {
@Inject
BasicWebSocketConnector connector;
void connectToClientEndpoint() {
connector.
.baseUri(uri)
.addHeader("X-Test", "foo")
.onTextMessage((connection, message) -> {
// you can access headers and other attrs of handshake req here
// if you also specify path params using SimpleWebSocketConnector#path() you can access these params here as well
connection.sendTextAndAwait(message);
})
.connectAndAwait();
}
}
|
Thanks a lot @mkouba! |
781168e
to
b471879
Compare
- add client endpoints and WebSocketConnector API - also includes refactoring of the server part so that we can reuse as much as possible
b471879
to
6dff924
Compare
I think that this pull request is now ready for the next round of review. Docs are still missing but I would like to add the client part in a follow-up pr. |
Status for workflow
|
We introduce 2 new concepts for the client part:
@WebSocketConnection
and built around theWebSocketClientConnection
(unlike@WebSocket
andWebSocketConnection
on the server)The
WebSocketConnector
can be injected in any bean:TODO
@OnTextMessage.broadcast()=true
/@OnBinaryMessage.broadcast()=true
on a client endpoint-removed from the list, not a high priority, maybe later...@WebSocketClient#autoConnect()
- connect the client automatically when the app startsNOTE: We decided to include the client part in the same extension as the server part. Therefore, we will get rid of
extensions/websockets-next/server
in a follow-up PR; i.e. the deployment module will be moved fromextensions/websockets-next/server/deployment
toextensions/websockets-next/deployment
and the runtime module will be moved fromextensions/websockets-next/server/runtime
toextensions/websockets-next/runtime
.