Uploaded image for project: 'Quarkus'
  1. Quarkus
  2. QUARKUS-5297

WebSockets Next: client endpoints

XMLWordPrintable

      • includes refactoring of the server part so that we can reuse as much as possible

      We introduce 2 new concepts for the client part:

      • client endpoints; using the same programming model as server endpoints, except that annotated with `@WebSocketConnection` and built around the `WebSocketClientConnection` (unlike `@WebSocket` and `WebSocketConnection` on the server)
      • WebSocket connector API - this API is used to configure and create new connections

      ```java
      @WebSocket(path = "/end/

      {name}")
      public class ServerEndpoint {
      @OnTextMessage
      String echo(String message, WebSocketConnection connection, @PathParam String name) { // do something with connection and name return message; }
      }

      @WebSocketClient(path = "/end/{name}

      ")
      public class ClientEndpoint {
      @OnTextMessage
      String echo(String message, WebSocketClientConnection connection, @PathParam String name)

      { // do something with connection and name return message; }

      }
      ```

      The `WebSocketConnector` can be injected in any bean:

      ```java
      @Singleton
      public class Service {

      @Inject
      WebSocketConnector<ClientEndpoint> connector;

      void connectToClientEndpoint()

      { connector. .baseUri(uri) // base URI is configurable per endpoint .pathParam("name", "Lu") .addHeader("X-Test", "foo") .connectAndAwait(); }

      }
      ```

        1. TODO
      • [x] add more tests
      • [x] fail the build if `@OnTextMessage.broadcast()=true`/ `@OnBinaryMessage.broadcast()=true` on a client endpoint
      • [x] Dev UI update (just make sure the server part works fine)

      ~-`@WebSocketClient#autoConnect()` - connect the client automatically when the app starts~ removed from the list, not a high priority, maybe later...

      NOTE: 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 from `extensions/websockets-next/server/deployment` to `extensions/websockets-next/deployment` and the runtime module will be moved from `extensions/websockets-next/server/runtime` to `extensions/websockets-next/runtime`.

              blafond Barry LaFond
              probinso_jira Quarkus JIRA Bot
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: