Skip to content

Commit

Permalink
WebSockets Next: document ping/pong messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mkouba committed Jun 17, 2024
1 parent dced341 commit 8c3d8e9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
26 changes: 22 additions & 4 deletions docs/src/main/asciidoc/websockets-next-reference.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -610,12 +610,28 @@ Item find(Item item) {
1. Specify the codec to use for both the deserialization of the incoming message

Check warning on line 610 in docs/src/main/asciidoc/websockets-next-reference.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.Spelling] Use correct American English spelling. Did you really mean 'codec'? Raw Output: {"message": "[Quarkus.Spelling] Use correct American English spelling. Did you really mean 'codec'?", "location": {"path": "docs/src/main/asciidoc/websockets-next-reference.adoc", "range": {"start": {"line": 610, "column": 5}}}, "severity": "WARNING"}

Check warning on line 610 in docs/src/main/asciidoc/websockets-next-reference.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.HeadingPunctuation] Do not use end punctuation in headings. Raw Output: {"message": "[Quarkus.HeadingPunctuation] Do not use end punctuation in headings.", "location": {"path": "docs/src/main/asciidoc/websockets-next-reference.adoc", "range": {"start": {"line": 610, "column": 71}}}, "severity": "INFO"}
2. Specify the codec to use for the serialization of the outgoing message

Check warning on line 611 in docs/src/main/asciidoc/websockets-next-reference.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.Spelling] Use correct American English spelling. Did you really mean 'codec'? Raw Output: {"message": "[Quarkus.Spelling] Use correct American English spelling. Did you really mean 'codec'?", "location": {"path": "docs/src/main/asciidoc/websockets-next-reference.adoc", "range": {"start": {"line": 611, "column": 5}}}, "severity": "WARNING"}

== Handle Pong message
== Ping/pong messages

The `@OnPongMessage` annotation is used to consume pong messages.
A websocket endpoint must declare at most one method annotated with `@OnPongMessage`.
A https://datatracker.ietf.org/doc/html/rfc6455#section-5.5.2[ping message] may serve as a keepalive or to verify the remote endpoint.

Check warning on line 615 in docs/src/main/asciidoc/websockets-next-reference.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.TermsWarnings] Consider using 'might (for possiblity)' or 'can (for ability)' rather than 'may' unless updating existing content that uses the term. Raw Output: {"message": "[Quarkus.TermsWarnings] Consider using 'might (for possiblity)' or 'can (for ability)' rather than 'may' unless updating existing content that uses the term.", "location": {"path": "docs/src/main/asciidoc/websockets-next-reference.adoc", "range": {"start": {"line": 615, "column": 66}}}, "severity": "WARNING"}

Check warning on line 615 in docs/src/main/asciidoc/websockets-next-reference.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.TermsSuggestions] Depending on the context, consider using 'because' or 'while' rather than 'as'. Raw Output: {"message": "[Quarkus.TermsSuggestions] Depending on the context, consider using 'because' or 'while' rather than 'as'.", "location": {"path": "docs/src/main/asciidoc/websockets-next-reference.adoc", "range": {"start": {"line": 615, "column": 76}}}, "severity": "INFO"}

Check warning on line 615 in docs/src/main/asciidoc/websockets-next-reference.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.Spelling] Use correct American English spelling. Did you really mean 'keepalive'? Raw Output: {"message": "[Quarkus.Spelling] Use correct American English spelling. Did you really mean 'keepalive'?", "location": {"path": "docs/src/main/asciidoc/websockets-next-reference.adoc", "range": {"start": {"line": 615, "column": 81}}}, "severity": "WARNING"}
A https://datatracker.ietf.org/doc/html/rfc6455#section-5.5.3[pong message] is sent in response to a ping message and it must have an identical payload.

The method must accept a single parameter of type `Buffer`:
The server automatically responds to a ping message sent from the client.
In other words, there is no need for `@OnPingMessage` callback declared on an endpoint.

The server can send ping messages to a connected client.
The `WebSocketConnection` declares methods to send ping messages; there is a non-blocking variant: `WebSocketConnection#sendPing(Buffer)` and a blocking variant: `WebSocketConnection#sendPingAndAwait(Buffer)`.
By default, the ping messages are not sent automatically.
However, the configuration property `quarkus.websockets-next.server.auto-ping-interval` can be used to set the interval after which, the server sends a ping message to a connected client automatically.

Check warning on line 624 in docs/src/main/asciidoc/websockets-next-reference.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.TermsSuggestions] Depending on the context, consider using ', which (non restrictive clause preceded by a comma)' or 'that (restrictive clause without a comma)' rather than 'which'. Raw Output: {"message": "[Quarkus.TermsSuggestions] Depending on the context, consider using ', which (non restrictive clause preceded by a comma)' or 'that (restrictive clause without a comma)' rather than 'which'.", "location": {"path": "docs/src/main/asciidoc/websockets-next-reference.adoc", "range": {"start": {"line": 624, "column": 115}}}, "severity": "INFO"}

[source,properties]
----
quarkus.websockets-next.server.auto-ping-interval=2 <1>
----
<1> Sends a ping message to a connected client every 2 seconds.

The `@OnPongMessage` annotation is used to define a callback that consumes pong messages sent from the client.
An endpoint must declare at most one method annotated with `@OnPongMessage`.
The callback method must return either `void` or `Uni<Void>`, and it must accept a single parameter of type `Buffer`.

[source,java]
----
Expand All @@ -625,6 +641,8 @@ void pong(Buffer data) {
}
----

NOTE: The server can also send unsolicited pong messages that may serve as a unidirectional heartbeat. There is a non-blocking variant: `WebSocketConnection#sendPong(Buffer)` and also a blocking variant: `WebSocketConnection#sendPongAndAwait(Buffer)`.

Check warning on line 644 in docs/src/main/asciidoc/websockets-next-reference.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.TermsWarnings] Consider using 'might (for possiblity)' or 'can (for ability)' rather than 'may' unless updating existing content that uses the term. Raw Output: {"message": "[Quarkus.TermsWarnings] Consider using 'might (for possiblity)' or 'can (for ability)' rather than 'may' unless updating existing content that uses the term.", "location": {"path": "docs/src/main/asciidoc/websockets-next-reference.adoc", "range": {"start": {"line": 644, "column": 52}}}, "severity": "WARNING"}

Check warning on line 644 in docs/src/main/asciidoc/websockets-next-reference.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.TermsSuggestions] Depending on the context, consider using 'because' or 'while' rather than 'as'. Raw Output: {"message": "[Quarkus.TermsSuggestions] Depending on the context, consider using 'because' or 'while' rather than 'as'.", "location": {"path": "docs/src/main/asciidoc/websockets-next-reference.adoc", "range": {"start": {"line": 644, "column": 62}}}, "severity": "INFO"}

[[websocket-next-security]]
== Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@
* <p>
* <ul>
* <li>Methods returning {@code void} are considered blocking and should be executed on a worker thread.</li>
* <li>Methods returning {@link io.smallrye.mutiny.Uni} or {@link io.smallrye.mutiny.Multi} are considered non-blocking and
* should be executed on an event loop thread.</li>
* <li>Methods returning any other type are considered blocking and should be executed on a worker thread.</li>
* <li>Methods returning {@code io.smallrye.mutiny.Uni<Void>} are considered non-blocking and should be executed on an event
* loop thread.</li>
* </ul>
*
* <h2>Method parameters</h2>
Expand Down

0 comments on commit 8c3d8e9

Please sign in to comment.