Starter for building RSocket clients and servers with Spring Boot auto-configuration.
npx @tessl/cli install tessl/maven-org-springframework-boot--spring-boot-starter-rsocket@2.7.0Spring Boot starter for building RSocket clients and servers. RSocket is a binary protocol for use on byte stream transports such as TCP, WebSockets, and Aeron. This starter provides comprehensive auto-configuration for RSocket infrastructure, making it easy to build reactive, real-time applications with bidirectional communication.
build.gradle or pom.xmldependencies {
implementation 'org.springframework.boot:spring-boot-starter-rsocket'
}<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-rsocket</artifactId>
</dependency>import org.springframework.messaging.rsocket.RSocketRequester;
import org.springframework.messaging.rsocket.RSocketStrategies;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.boot.rsocket.server.RSocketServerCustomizer;
import org.springframework.boot.autoconfigure.rsocket.RSocketStrategiesCustomizer;
import org.springframework.boot.rsocket.context.LocalRSocketServerPort; // Deprecated
import org.springframework.boot.rsocket.context.RSocketServerInitializedEvent;
import org.springframework.boot.test.rsocket.server.LocalRSocketServerPort; // Replacement since 2.7.0@Service
public class MyRSocketClient {
private final RSocketRequester.Builder requesterBuilder;
public MyRSocketClient(RSocketRequester.Builder requesterBuilder) {
this.requesterBuilder = requesterBuilder;
}
public Mono<String> callServer() {
return requesterBuilder
.tcp("localhost", 9898)
.route("hello")
.data("World")
.retrieveMono(String.class);
}
}@Controller
public class MyRSocketController {
@MessageMapping("hello")
public Mono<String> hello(String name) {
return Mono.just("Hello, " + name + "!");
}
}# application.yml
spring:
rsocket:
server:
port: 9898
transport: tcpThe starter provides several key layers:
Automatic configuration of RSocket infrastructure including codecs, servers, clients, and messaging handlers. Provides sensible defaults while enabling extensive customization through properties and customizer beans.
// Auto-configuration classes registered automatically
@AutoConfiguration(after = JacksonAutoConfiguration.class)
@ConditionalOnClass({ io.rsocket.RSocket.class, RSocketStrategies.class, PooledByteBufAllocator.class })
class RSocketStrategiesAutoConfiguration {
@Bean
@ConditionalOnMissingBean
RSocketStrategies rSocketStrategies(ObjectProvider<RSocketStrategiesCustomizer> customizers);
}
@AutoConfiguration(after = RSocketStrategiesAutoConfiguration.class)
@ConditionalOnClass({ RSocketServer.class, RSocketStrategies.class, HttpServer.class, TcpServerTransport.class })
@ConditionalOnBean(RSocketMessageHandler.class)
@EnableConfigurationProperties(RSocketProperties.class)
class RSocketServerAutoConfiguration {
// Server configuration classes
}
@AutoConfiguration(after = RSocketStrategiesAutoConfiguration.class)
@ConditionalOnClass({ RSocketRequester.class, io.rsocket.RSocket.class, HttpServer.class, TcpServerTransport.class })
class RSocketRequesterAutoConfiguration {
@Bean
@Scope("prototype")
@ConditionalOnMissingBean
RSocketRequester.Builder rSocketRequesterBuilder(RSocketStrategies strategies, ObjectProvider<RSocketConnectorConfigurer> connectorConfigurers);
}
@AutoConfiguration(after = RSocketStrategiesAutoConfiguration.class)
@ConditionalOnClass({ RSocketRequester.class, io.rsocket.RSocket.class, TcpServerTransport.class })
class RSocketMessagingAutoConfiguration {
@Bean
@ConditionalOnMissingBean
RSocketMessageHandler messageHandler(RSocketStrategies rSocketStrategies, ObjectProvider<RSocketMessageHandlerCustomizer> customizers);
}RSocket server setup supporting both standalone TCP/WebSocket servers and WebSocket endpoints integrated with Spring WebFlux applications.
// Server configuration properties
@ConfigurationProperties("spring.rsocket.server")
class RSocketProperties.Server {
Integer port;
InetAddress address;
RSocketServer.Transport transport; // TCP, WEBSOCKET
String mappingPath;
DataSize fragmentSize;
Ssl ssl;
}RSocket client configuration with RSocketRequester builder for establishing connections and making requests to RSocket servers.
@Bean
@Scope("prototype")
@ConditionalOnMissingBean
RSocketRequester.Builder rSocketRequesterBuilder(
RSocketStrategies strategies,
ObjectProvider<RSocketConnectorConfigurer> connectorConfigurers
);Spring messaging integration enabling @MessageMapping annotations and bidirectional communication patterns in RSocket controllers.
@Bean
@ConditionalOnMissingBean
RSocketMessageHandler messageHandler(
RSocketStrategies rSocketStrategies,
ObjectProvider<RSocketMessageHandlerCustomizer> customizers
);Encoding and decoding configuration for RSocket payloads, with built-in support for JSON and CBOR formats via Jackson integration.
@Bean
@ConditionalOnMissingBean
RSocketStrategies rSocketStrategies(
ObjectProvider<RSocketStrategiesCustomizer> customizers
);All RSocket configuration is available under the spring.rsocket prefix:
spring:
rsocket:
server:
port: 9898 # Server port
address: 0.0.0.0 # Bind address
transport: tcp # TCP or WEBSOCKET
mapping-path: "/rsocket" # WebSocket path
fragment-size: 64KB # Frame fragmentation
ssl:
enabled: true # SSL configuration// Core server interface
interface RSocketServer {
void start() throws RSocketServerException;
void stop() throws RSocketServerException;
InetSocketAddress address();
enum Transport { TCP, WEBSOCKET }
}
// Server factory interface
@FunctionalInterface
interface RSocketServerFactory {
RSocketServer create(SocketAcceptor socketAcceptor);
}
// Configurable server factory interface
interface ConfigurableRSocketServerFactory extends RSocketServerFactory {
void setPort(int port);
void setAddress(InetAddress address);
void setTransport(RSocketServer.Transport transport);
}
// Server bootstrap for lifecycle management
class RSocketServerBootstrap implements SmartLifecycle {
RSocketServerBootstrap(RSocketServerFactory serverFactory, SocketAcceptor socketAcceptor);
void start();
void stop();
boolean isRunning();
}
// Server initialization event
class RSocketServerInitializedEvent extends ApplicationEvent {
RSocketServerInitializedEvent(RSocketServer server);
RSocketServer getServer();
}
// Port injection annotation (deprecated since 2.7.0)
@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Value("${local.rsocket.server.port}")
@Deprecated
@interface LocalRSocketServerPort {
}
// Server exceptions
class RSocketServerException extends RuntimeException {
RSocketServerException(String message, Throwable cause);
}
// Customization interfaces
@FunctionalInterface
interface RSocketStrategiesCustomizer {
void customize(RSocketStrategies.Builder strategies);
}
@FunctionalInterface
interface RSocketMessageHandlerCustomizer {
void customize(RSocketMessageHandler messageHandler);
}
@FunctionalInterface
interface RSocketServerCustomizer {
void customize(RSocketServer server);
}
// RSocket connector configurer interface
@FunctionalInterface
interface RSocketConnectorConfigurer {
void configure(RSocketConnector.RSocketConnectorBuilder builder);
}
// Configuration properties
@ConfigurationProperties("spring.rsocket")
class RSocketProperties {
Server server;
static class Server {
Integer port;
InetAddress address;
RSocketServer.Transport transport;
String mappingPath;
DataSize fragmentSize;
Ssl ssl;
}
}