From 0ab1c1a94f27be14a29f59aafb61786c97f44f79 Mon Sep 17 00:00:00 2001 From: Martin Kouba Date: Tue, 4 Jun 2024 10:07:47 +0200 Subject: [PATCH] WebSockets Next: document OpenConnections - resolves #40546 --- .../asciidoc/websockets-next-reference.adoc | 25 +++++++++++++++++++ .../asciidoc/websockets-next-tutorial.adoc | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/docs/src/main/asciidoc/websockets-next-reference.adoc b/docs/src/main/asciidoc/websockets-next-reference.adoc index 9260687981444..dc0d890d721ca 100644 --- a/docs/src/main/asciidoc/websockets-next-reference.adoc +++ b/docs/src/main/asciidoc/websockets-next-reference.adoc @@ -496,6 +496,31 @@ The `WebSocketConnection` provides both a blocking and a non-blocking method to - `sendTextAndAwait(String message)`: Sends a text message to the client and waits for the message to be sent. It's blocking and should only be called from an executor thread. - `sendText(String message)`: Sends a text message to the client. It returns a `Uni`. It's non-blocking, but you must subscribe to it. +=== List open connections + +It is also possible to list all open connections. +Quarkus provides a CDI bean of type `io.quarkus.websockets.next.OpenConnections` that declares convenient methods to access the connections. + +[source, java] +---- +import io.quarkus.logging.Log; +import io.quarkus.websockets.next.OpenConnections; + +class MyBean { + + @Inject + OpenConnections connections; + + void logAllOpenConnections() { + Log.infof("Open connections: %s", connections.listAll()); <1> + } +} +---- +<1> `OpenConnections#listAll()` returns an immutable snapshot of all open connections at the given time. + +There are also other convenient methods. +For example, `OpenConnections#findByEndpointId(String)` makes it easy to find connections for a specific endpoint. + == Serialization and Deserialization The WebSocket Next extension supports automatic serialization and deserialization of messages. diff --git a/docs/src/main/asciidoc/websockets-next-tutorial.adoc b/docs/src/main/asciidoc/websockets-next-tutorial.adoc index 91a67eda53e3a..0e1756cf25f10 100644 --- a/docs/src/main/asciidoc/websockets-next-tutorial.adoc +++ b/docs/src/main/asciidoc/websockets-next-tutorial.adoc @@ -3,7 +3,7 @@ This guide is maintained in the main Quarkus repository and pull requests should be submitted there: https://github.com/quarkusio/quarkus/tree/main/docs/src/main/asciidoc //// -= Getting started with WebSockets-Next += Getting started with WebSockets Next include::_attributes.adoc[] :categories: web :diataxis-type: tutorial