Skip to content

Commit d6a5c34

Browse files
committed
Improve docs on STOMP / WebSocket frame max size
Issue: SPR-17514
1 parent 24848ec commit d6a5c34

File tree

2 files changed

+41
-13
lines changed

2 files changed

+41
-13
lines changed

spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebSocketTransportRegistration.java

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,12 @@ public class WebSocketTransportRegistration {
4747

4848

4949
/**
50-
* Configure the maximum size for an incoming sub-protocol message.
51-
* For example a STOMP message may be received as multiple WebSocket messages
52-
* or multiple HTTP POST requests when SockJS fallback options are in use.
53-
* <p>In theory a WebSocket message can be almost unlimited in size.
54-
* In practice WebSocket servers impose limits on incoming message size.
55-
* STOMP clients for example tend to split large messages around 16K
56-
* boundaries. Therefore a server must be able to buffer partial content
57-
* and decode when enough data is received. Use this property to configure
58-
* the max size of the buffer to use.
50+
* Configure the maximum size of an inbound sub-protocol message, such as
51+
* a STOMP frame which may be aggregated from multiple WebSocket messages.
5952
* <p>The default value is 64K (i.e. 64 * 1024).
60-
* <p><strong>NOTE</strong> that the current version 1.2 of the STOMP spec
61-
* does not specifically discuss how to send STOMP messages over WebSocket.
62-
* Version 2 of the spec will but in the mean time existing client libraries
63-
* have already established a practice that servers must handle.
53+
* <p><strong>Note:</strong> This is not the same as the size of an
54+
* individual WebSocket message which needs to be configured at the WebSocket
55+
* server level instead. See the reference documentation for details.
6456
*/
6557
public WebSocketTransportRegistration setMessageSizeLimit(int messageSizeLimit) {
6658
this.messageSizeLimit = messageSizeLimit;

src/docs/asciidoc/web/websocket.adoc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,42 @@ application.
11331133

11341134

11351135

1136+
[[websocket-stomp-server-config]]
1137+
=== WebSocket Server
1138+
1139+
To configure the underlying WebSocket server, the information in
1140+
<<websocket-server-runtime-configuration>> applies. For Jetty, however you need to set
1141+
the `HandshakeHandler` and `WebSocketPolicy` through the `StompEndpointRegistry`:
1142+
1143+
====
1144+
[source,java,indent=0]
1145+
[subs="verbatim,quotes"]
1146+
----
1147+
@Configuration
1148+
@EnableWebSocketMessageBroker
1149+
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
1150+
1151+
@Override
1152+
public void registerStompEndpoints(StompEndpointRegistry registry) {
1153+
registry.addEndpoint("/portfolio").setHandshakeHandler(handshakeHandler());
1154+
}
1155+
1156+
@Bean
1157+
public DefaultHandshakeHandler handshakeHandler() {
1158+
1159+
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
1160+
policy.setInputBufferSize(8192);
1161+
policy.setIdleTimeout(600000);
1162+
1163+
return new DefaultHandshakeHandler(
1164+
new JettyRequestUpgradeStrategy(new WebSocketServerFactory(policy)));
1165+
}
1166+
}
1167+
----
1168+
====
1169+
1170+
1171+
11361172
[[websocket-stomp-message-flow]]
11371173
=== Flow of Messages
11381174

0 commit comments

Comments
 (0)