spring-boot - 如何在spring boot(使用netty服务器)中启用websocket消息压缩deflate(使用rsocket协议(protocol))

标签 spring-boot websocket compression netty rsocket

我想使用 websocket 和 rsocket 在 netty 环境中的服务器端启用 permessage-deflate 压缩。我现在的握手看起来像这样:

enter image description here

我正在使用依赖项:

 <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)));
}

enter image description here

关于spring-boot - 如何在spring boot(使用netty服务器)中启用websocket消息压缩deflate(使用rsocket协议(protocol)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64802242/

相关文章:

postgresql tcp数据压缩

iphone - AVAssetExportSession 输出文件

java - 我们可以在单个 spring boot 应用程序中使用多个 yaml 文件吗?

java - url 中的 Spring-boot 位置变量

amazon-web-services - 适用于Websocket应用程序的更好的AWS自动扩展和负载平衡策略

php - 将配置数据发送到 websocket

mysql - 如何将 mysql-client 连接到我的 Spring Boot 应用程序

java - Spring MVC 中的延迟计算

spring - 订阅不工作 Spring SockJs Stomp

Git 存储库压缩后比未压缩更大