如何解决如何在春季启动使用Netty服务器中启用Websocket消息压缩放气使用rsocket协议
我想在netty环境中使用websocket和rsocket在服务器端启用permessage-deflate压缩。我的握手现在看起来像这样:
我正在使用依赖项:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-websocket</artifactId>
<version>5.2.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-messaging</artifactId>
<version>5.2.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-rsocket</artifactId>
</dependency>
spring boot中是否有任何属性来支持此功能?
解决方法
默认情况下,在 netty 环境中,服务器端禁用 permessage-deflate 压缩。
您需要使用 reactor-netty 定义一个 bean WebSocketService
并将压缩设置为 true 以激活它:
@Bean
public WebSocketHandlerAdapter handlerAdapter(WebSocketService webSocketService) {
return new WebSocketHandlerAdapter(webSocketService);
}
@Bean
public WebSocketService webSocketService() {
return new HandshakeWebSocketService(
new ReactorNettyRequestUpgradeStrategy(WebsocketServerSpec.builder().compress(true)));
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。