-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
Unable to make WebSocket transport compression work in RSocket client/server Spring Boot applications running with Netty backend and Spring Boot version 2.5.9.
The Spring Boot allows to specify the server-side RSocket transport and endpoint path in the application.properties, but there are no any additional configuration parameters available besides that. The autoconfig creates an instance of the RSocketWebSocketNettyRouteProvider
which doesn't have compression enabled and also doesn't have any customizers to enable it.
To get around that I removed spring.rsocket.server.mapping-path
property and declared a bean like this in the server config to pass a WebsocketServerSpec
with compress option enabled to httpServerRoutes.ws(...)
call:
@Bean
NettyRouteProvider rSocketWebsocketRouteProvider(
RSocketProperties properties, RSocketMessageHandler messageHandler,
ObjectProvider<RSocketServerCustomizer> customizers) {
return new NettyRouteProvider() {
public HttpServerRoutes apply(HttpServerRoutes httpServerRoutes) {
RSocketServer server = RSocketServer.create(messageHandler.responder());
customizers.forEach((customizer) -> customizer.customize(server));
return httpServerRoutes.ws("/rsocket",
WebsocketRouteTransport.newHandler(server.asConnectionAcceptor()),
WebsocketServerSpec.builder().compress(true).build());
}
};
}
On the client side I'm creating RSocketRequester
like this:
RSocketRequester requester = builder
.setupRoute("/backend/connect")
.setupData(id)
.rsocketConnector(connector -> connector
.reconnect(Retry.fixedDelay(Integer.MAX_VALUE, Duration.ofSeconds(5)))
.acceptor(RSocketMessageHandler.responder(strategies, backendController)) // ****** (1)
)
.dataMimeType(MediaType.APPLICATION_JSON)
.transport(() -> {
// httpClient is immutable - baseUrl() creates a copy
ClientTransport t = WebsocketClientTransport.create(
HttpClient.create().baseUrl(backendUrl), "/rsocket")
.webSocketSpec(configurer -> configurer
.compress(true) // ****** (2)
.maxFramePayloadLength(65536));
return t.connect();
});
The webSocketSpec
need to have compress flag enabled. Otherwise I don't see compression applied when looking at the traffic in Charles proxy with a simple port forwarding enabled.
The problem is that when compress is enabled on line (2) the client can't complete the connection sequence.
However if I comment out the .acceptor()
configuration on line (1) the connect is working and I see server to client calls going through and I can see data is being compressed. But without the acceptor server can't call the client.
Here is an example project repository https://github.com/maximdim/rsocket2/tree/rsocket-compression
You can launch BackendApplication
and AgentApplication
to observe described issue.