How to enable websocket message compression deflate (with rsocket protocol) in spring boot (with netty server)

Viewed 430

I want to enable permessage-deflate compression on server side in netty environment using websocket and rsocket. My handshake right now look like this:

enter image description here

I am using dependencies:

 <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>

Is any property in spring boot to support this functionality?

1 Answers

By default the permessage-deflate compression is disabled on the server side in netty environment. You need to define a bean WebSocketService with reactor-netty and set the compression to true to activate it:

@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

Related