Skip to content

Commit

Permalink
Merge pull request #40955 from mkouba/issue-40546
Browse files Browse the repository at this point in the history
WebSockets Next: document OpenConnections
  • Loading branch information
mkouba authored Jun 4, 2024
2 parents aad3d22 + 0ab1c1a commit 9697164
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions docs/src/main/asciidoc/websockets-next-reference.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion docs/src/main/asciidoc/websockets-next-tutorial.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9697164

Please sign in to comment.