CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-springframework-boot--spring-boot-starter-rsocket

Starter for building RSocket clients and servers with Spring Boot auto-configuration.

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

Spring Boot Starter RSocket

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

Package Information

  • Package Name: spring-boot-starter-rsocket
  • Package Type: maven
  • Language: Java
  • Installation: Add to build.gradle or pom.xml
dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-rsocket'
}
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-rsocket</artifactId>
</dependency>

Core Imports

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

Basic Usage

Client Configuration

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

Server Configuration

@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: tcp

Architecture

The starter provides several key layers:

  • Auto-Configuration: Automatically configures RSocket infrastructure based on classpath and properties
  • Strategy Layer: RSocketStrategies for codec configuration and message handling
  • Server Infrastructure: Embedded RSocket server or WebSocket integration with WebFlux
  • Client Infrastructure: RSocketRequester builder for creating client connections
  • Messaging Integration: Spring messaging annotations and handlers for RSocket endpoints
  • Customization Points: Multiple customizer interfaces for fine-tuning configuration

Capabilities

Auto-Configuration

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

Auto-Configuration

Server Configuration

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

Server Configuration

Client Configuration

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

Client Configuration

Message Handling

Spring messaging integration enabling @MessageMapping annotations and bidirectional communication patterns in RSocket controllers.

@Bean
@ConditionalOnMissingBean
RSocketMessageHandler messageHandler(
    RSocketStrategies rSocketStrategies,
    ObjectProvider<RSocketMessageHandlerCustomizer> customizers
);

Message Handling

Codec Configuration

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

Codec Configuration

Configuration Properties

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

Types

// 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;
    }
}
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.springframework.boot/spring-boot-starter-rsocket@2.7.x
Publish Source
CLI
Badge
tessl/maven-org-springframework-boot--spring-boot-starter-rsocket badge