本文主要是介绍Spring STOMP-WebSocket传输消息,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
本节介绍怎么配置底层的WebSocket服务器的消息传输。
对于Jakarta WebSocket服务器,在项目配置中添加一个ServletServerContainerFactoryBean
。例如,请参阅WebSocket部分下的配置服务器。
对于Jetty WebSocket服务器,如下这个例子自定义了JettyRequestUpgradeStrategy
:
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {@Overridepublic void registerStompEndpoints(StompEndpointRegistry registry) {registry.addEndpoint("/portfolio").setHandshakeHandler(handshakeHandler());}@Beanpublic DefaultHandshakeHandler handshakeHandler() {JettyRequestUpgradeStrategy strategy = new JettyRequestUpgradeStrategy();strategy.addWebSocketConfigurer(configurable -> {policy.setInputBufferSize(4 * 8192);policy.setIdleTimeout(600000);});return new DefaultHandshakeHandler(strategy);}
}
除了WebSocket服务器的属性外,还有一些STOMP WebSocket传输消息相关的属性可以自定义,如下所示:
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {@Overridepublic void configureWebSocketTransport(WebSocketTransportRegistration registry) {registry.setMessageSizeLimit(4 * 8192);registry.setTimeToFirstMessage(30000);}
}
这篇关于Spring STOMP-WebSocket传输消息的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!