Browse Source

Update STOMP WebSocket transport reference docs

Closes gh-31616
pull/33657/head
rstoyanchev 2 years ago
parent
commit
1f19bb2311
  1. 48
      framework-docs/modules/ROOT/pages/web/websocket/server.adoc
  2. 28
      framework-docs/modules/ROOT/pages/web/websocket/stomp/server-config.adoc

48
framework-docs/modules/ROOT/pages/web/websocket/server.adoc

@ -229,34 +229,27 @@ Java initialization API. The following example shows how to do so:
[[websocket-server-runtime-configuration]] [[websocket-server-runtime-configuration]]
== Server Configuration == Configuring the Server
[.small]#xref:web/webflux-websocket.adoc#webflux-websocket-server-config[See equivalent in the Reactive stack]# [.small]#xref:web/webflux-websocket.adoc#webflux-websocket-server-config[See equivalent in the Reactive stack]#
Each underlying WebSocket engine exposes configuration properties that control You can configure of the underlying WebSocket server such as input message buffer size,
runtime characteristics, such as the size of message buffer sizes, idle timeout, idle timeout, and more.
and others.
For Tomcat, WildFly, and GlassFish, you can add a `ServletServerContainerFactoryBean` to your For Jakarta WebSocket servers, you can add a `ServletServerContainerFactoryBean` to your
WebSocket Java config, as the following example shows: Java configuration. For example:
[source,java,indent=0,subs="verbatim,quotes"] [source,java,indent=0,subs="verbatim,quotes"]
---- ----
@Configuration @Bean
@EnableWebSocket public ServletServerContainerFactoryBean createWebSocketContainer() {
public class WebSocketConfig implements WebSocketConfigurer { ServletServerContainerFactoryBean container = new ServletServerContainerFactoryBean();
container.setMaxTextMessageBufferSize(8192);
@Bean container.setMaxBinaryMessageBufferSize(8192);
public ServletServerContainerFactoryBean createWebSocketContainer() { return container;
ServletServerContainerFactoryBean container = new ServletServerContainerFactoryBean(); }
container.setMaxTextMessageBufferSize(8192);
container.setMaxBinaryMessageBufferSize(8192);
return container;
}
}
---- ----
The following example shows the XML configuration equivalent of the preceding example: Or to your XML configuration:
[source,xml,indent=0,subs="verbatim,quotes,attributes"] [source,xml,indent=0,subs="verbatim,quotes,attributes"]
---- ----
@ -277,12 +270,11 @@ The following example shows the XML configuration equivalent of the preceding ex
</beans> </beans>
---- ----
NOTE: For client-side WebSocket configuration, you should use `WebSocketContainerFactoryBean` NOTE: For client Jakarta WebSocket configuration, use
(XML) or `ContainerProvider.getWebSocketContainer()` (Java configuration). ContainerProvider.getWebSocketContainer() in Java configuration, or
`WebSocketContainerFactoryBean` in XML.
For Jetty, you need to supply a pre-configured Jetty `WebSocketServerFactory` and plug For Jetty, you can supply a `Consumer` callback to configure the WebSocket server:
that into Spring's `DefaultHandshakeHandler` through your WebSocket Java config.
The following example shows how to do so:
[source,java,indent=0,subs="verbatim,quotes"] [source,java,indent=0,subs="verbatim,quotes"]
---- ----
@ -298,11 +290,9 @@ The following example shows how to do so:
@Bean @Bean
public DefaultHandshakeHandler handshakeHandler() { public DefaultHandshakeHandler handshakeHandler() {
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER); WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
policy.setInputBufferSize(8192); policy.setInputBufferSize(8192);
policy.setIdleTimeout(600000); policy.setIdleTimeout(600000);
return new DefaultHandshakeHandler( return new DefaultHandshakeHandler(
new JettyRequestUpgradeStrategy(new WebSocketServerFactory(policy))); new JettyRequestUpgradeStrategy(new WebSocketServerFactory(policy)));
} }
@ -349,6 +339,10 @@ The following example shows the XML configuration equivalent of the preceding ex
</beans> </beans>
---- ----
TIP: When using STOMP over WebSocket, you will also need to configure
xref:web/websocket/stomp/server-config.adoc[STOMP WebSocket transport]
properties.
[[websocket-server-allowed-origins]] [[websocket-server-allowed-origins]]

28
framework-docs/modules/ROOT/pages/web/websocket/stomp/server-config.adoc

@ -1,9 +1,14 @@
[[websocket-stomp-server-config]] [[websocket-stomp-server-config]]
= WebSocket Server = WebSocket Transport
To configure the underlying WebSocket server, the information in This section explains how to configure the underlying WebSocket server transport.
xref:web/websocket/server.adoc#websocket-server-runtime-configuration[Server Configuration] applies. For Jetty, however you need to set
the `HandshakeHandler` and `WebSocketPolicy` through the `StompEndpointRegistry`: For Jakarta WebSocket servers, add a `ServletServerContainerFactoryBean` to your
configuration. For examples, see
xref:web/websocket/server.adoc#websocket-server-runtime-configuration[Configuring the Server]
under the WebSocket section.
For Jetty WebSocket servers, customize the `JettyRequestUpgradeStrategy` as follows:
[source,java,indent=0,subs="verbatim,quotes"] [source,java,indent=0,subs="verbatim,quotes"]
---- ----
@ -29,5 +34,20 @@ the `HandshakeHandler` and `WebSocketPolicy` through the `StompEndpointRegistry`
} }
---- ----
In addition to WebSocket server properties, there are also STOMP WebSocket transport properties
to customize as follows:
[source,java,indent=0,subs="verbatim,quotes"]
----
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
@Override
public void configureWebSocketTransport(WebSocketTransportRegistration registry) {
registry.setMessageSizeLimit(4 * 8192);
registry.setTimeToFirstMessage(30000);
}
}
----

Loading…
Cancel
Save