Skip to content

Commit 9ac9135

Browse files
committed
Update reference on StompClient
Issue: SPR-13664
1 parent c520097 commit 9ac9135

File tree

1 file changed

+34
-26
lines changed

1 file changed

+34
-26
lines changed

src/asciidoc/web-websocket.adoc

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,41 +1884,40 @@ to access information about the message.
18841884
[[websocket-stomp-client]]
18851885
=== STOMP Client
18861886

1887-
Spring provides STOMP/WebSocket client and STOMP/TCP client support with the
1888-
following built-in choices (other libraries can be adapted):
1887+
Spring provides a STOMP over WebSocket client and a STOMP over TCP client.
18891888

1890-
* `WebSocketStompClient` built on the Spring WebSocket API with
1891-
support for standard JSR-356 WebSocket, Jetty 9, as well as SockJS
1892-
for HTTP-based WebSocket emulation (see <<websocket-fallback-sockjs-client>>).
1893-
* `Reactor11TcpStompClient` built on `NettyTcpClient` from the reactor-net project.
1894-
1895-
To begin, create and configure the client:
1889+
To begin create and configure `WebSocketStompClient`:
18961890

18971891
[source,java,indent=0]
18981892
[subs="verbatim,quotes"]
18991893
----
1900-
WebSocketClient transport = new StandardWebSocketClient();
1901-
WebSocketStompClient stompClient = new WebSocketStompClient(transport);
1894+
WebSocketClient webSocketClient = new StandardWebSocketClient();
1895+
WebSocketStompClient stompClient = new WebSocketStompClient(webSocketClient);
19021896
stompClient.setMessageConverter(new StringMessageConverter());
1903-
stompClient.setTaskScheduler(taskScheduler); // for heartbeats, receipts
1897+
stompClient.setTaskScheduler(taskScheduler); // for heartbeats
19041898
----
19051899

1906-
Then connect to the WebSocket and provide a handler for the STOMP session:
1900+
In the above example `StandardWebSocketClient` could be replaced with `SockJsClient`
1901+
since that is also an implementation of `WebSocketClient`. The `SockJsClient` can
1902+
use WebSocket or HTTP-based transport as a fallback. For more details see
1903+
<<websocket-fallback-sockjs-client>>.
1904+
1905+
Next establish a connection and provide a handler for the STOMP session:
19071906

19081907
[source,java,indent=0]
19091908
[subs="verbatim,quotes"]
19101909
----
19111910
String url = "ws://127.0.0.1:8080/endpoint";
1912-
StompSessionHandler handler = ... ;
1913-
stompClient.connect(url, handler);
1911+
StompSessionHandler sessionHandler = new MyStompSessionHandler();
1912+
stompClient.connect(url, sessionHandler);
19141913
----
19151914

1916-
When the session is ready for use, the handler is notified:
1915+
When the session is ready for use the handler is notified:
19171916

19181917
[source,java,indent=0]
19191918
[subs="verbatim,quotes"]
19201919
----
1921-
public class MySessionHandler extends StompSessionHandlerAdapter {
1920+
public class MyStompSessionHandler extends StompSessionHandlerAdapter {
19221921
19231922
@Override
19241923
public void afterConnected(StompSession session, StompHeaders connectedHeaders) {
@@ -1927,18 +1926,19 @@ public class MySessionHandler extends StompSessionHandlerAdapter {
19271926
}
19281927
----
19291928

1930-
Send any Object as the payload and it will be serialized with a `MessageConverter`:
1929+
Once the session is established any payload can be sent and that will be
1930+
serialized with the configured `MessageConverter`:
19311931

19321932
[source,java,indent=0]
19331933
[subs="verbatim,quotes"]
19341934
----
19351935
session.send("/topic/foo", "payload");
19361936
----
19371937

1938-
The subscribe methods take a `StompFrameHandler` for messages on the subscription
1939-
and return a `Subscription` handle for unsubscribing. For each received message,
1940-
the handler must help to select the target type and then handle the
1941-
deserialized payload:
1938+
You can also subscribe to destinations. The `subscribe` methods require a handler
1939+
for messages on the subscription and return a `Subscription` handle that can be
1940+
used to unsubscribe. For each received message the handler can specify the target
1941+
Object type the payload should be deserialized to:
19421942

19431943
[source,java,indent=0]
19441944
[subs="verbatim,quotes"]
@@ -1958,11 +1958,19 @@ session.subscribe("/topic/foo", new StompFrameHandler() {
19581958
});
19591959
----
19601960

1961-
STOMP supports heartbeats. To use this feature simply configure the
1962-
`WebSocketStompClient` with a `TaskScheduler` and if desired customize the
1963-
default heartbeat intervals (10, 10 seconds respectively by default) for
1964-
write inactivity which causes a heartbeat to be sent and for read
1965-
inactivity which closes the connection.
1961+
To enable STOMP heartbeat configure `WebSocketStompClient` with a `TaskScheduler`
1962+
and optionally customize the heartbeat intervals, 10 seconds for write inactivity
1963+
which causes a heartbeat to be sent and 10 seconds for read inactivity which
1964+
closes the connection.
1965+
1966+
[NOTE]
1967+
====
1968+
When using `WebSocketStompClient` for performance tests to simulate thousands
1969+
of clients from the same machine consider turning off heartbeats since each
1970+
connection schedules its own heartbeat tasks and that's not optimized for a
1971+
a large number of clients running on the same machine.
1972+
====
1973+
19661974

19671975
The STOMP protocol also supports receipts where the client must add a "receipt"
19681976
header to which the server responds with a RECEIPT frame after the send or

0 commit comments

Comments
 (0)