or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

auto-configuration.mdclient-configuration.mdcodec-configuration.mdindex.mdmessage-handling.mdserver-configuration.md

server-configuration.mddocs/

0

# Server Configuration

1

2

RSocket server setup supporting both standalone TCP/WebSocket servers and WebSocket endpoints integrated with Spring WebFlux applications.

3

4

## Capabilities

5

6

### Server Properties Configuration

7

8

Configure RSocket servers through Spring Boot properties under the `spring.rsocket.server` prefix.

9

10

```java { .api }

11

/**

12

* Configuration properties for RSocket server

13

*/

14

@ConfigurationProperties("spring.rsocket.server")

15

class RSocketProperties.Server {

16

17

/** Server port - required for standalone server */

18

Integer port;

19

20

/** Network address to bind (default: all interfaces) */

21

InetAddress address;

22

23

/** Transport protocol */

24

RSocketServer.Transport transport; // TCP, WEBSOCKET

25

26

/** WebSocket mapping path (WebSocket transport only) */

27

String mappingPath;

28

29

/** Maximum frame size before fragmentation */

30

DataSize fragmentSize;

31

32

/** SSL configuration */

33

Ssl ssl;

34

}

35

36

/**

37

* RSocket server transport options

38

*/

39

enum RSocketServer.Transport {

40

TCP, // Direct TCP transport

41

WEBSOCKET // WebSocket transport

42

}

43

```

44

45

**Configuration Examples:**

46

47

```yaml

48

# Standalone TCP server

49

spring:

50

rsocket:

51

server:

52

port: 9898

53

transport: tcp

54

address: 0.0.0.0

55

fragment-size: 64KB

56

57

# WebSocket integration with WebFlux

58

spring:

59

rsocket:

60

server:

61

transport: websocket

62

mapping-path: "/rsocket"

63

64

# SSL-enabled server

65

spring:

66

rsocket:

67

server:

68

port: 9899

69

ssl:

70

enabled: true

71

key-store: classpath:keystore.p12

72

key-store-password: secret

73

```

74

75

### Standalone Server Factory

76

77

Factory for creating standalone RSocket servers with custom configuration.

78

79

```java { .api }

80

/**

81

* Factory interface for creating RSocket servers

82

*/

83

@FunctionalInterface

84

interface RSocketServerFactory {

85

RSocketServer create(SocketAcceptor socketAcceptor);

86

}

87

88

/**

89

* Configurable RSocket server factory interface

90

*/

91

interface ConfigurableRSocketServerFactory {

92

/** Set server port (default: 9898) */

93

void setPort(int port);

94

95

/** Set network bind address */

96

void setAddress(InetAddress address);

97

98

/** Set transport protocol (TCP/WebSocket) */

99

void setTransport(RSocketServer.Transport transport);

100

101

/** Set maximum frame size for fragmentation */

102

void setFragmentSize(DataSize fragmentSize);

103

104

/** Configure SSL settings */

105

void setSsl(Ssl ssl);

106

107

/** Set SSL store provider */

108

void setSslStoreProvider(SslStoreProvider sslStoreProvider);

109

}

110

111

/**

112

* Netty-based RSocket server factory implementation

113

*/

114

class NettyRSocketServerFactory implements RSocketServerFactory, ConfigurableRSocketServerFactory {

115

116

/** Set server bind address */

117

void setAddress(InetAddress address);

118

119

/** Set server port */

120

void setPort(int port);

121

122

/** Set transport protocol (TCP/WebSocket) */

123

void setTransport(RSocketServer.Transport transport);

124

125

/** Configure frame fragmentation size */

126

void setFragmentSize(DataSize fragmentSize);

127

128

/** Configure SSL settings */

129

void setSsl(Ssl ssl);

130

131

/** Set SSL store provider */

132

void setSslStoreProvider(SslStoreProvider sslStoreProvider);

133

134

/** Set Reactor Netty resource factory */

135

void setResourceFactory(ReactorResourceFactory resourceFactory);

136

137

/** Set server customizers */

138

void setRSocketServerCustomizers(List<RSocketServerCustomizer> customizers);

139

140

@Override

141

RSocketServer create(SocketAcceptor socketAcceptor);

142

}

143

```

144

145

**Usage Example:**

146

147

```java

148

@Configuration

149

public class CustomServerConfiguration {

150

151

@Bean

152

@ConditionalOnMissingBean

153

public RSocketServerFactory customRSocketServerFactory() {

154

NettyRSocketServerFactory factory = new NettyRSocketServerFactory();

155

factory.setPort(9999);

156

factory.setTransport(RSocketServer.Transport.TCP);

157

factory.setFragmentSize(DataSize.ofKilobytes(32));

158

return factory;

159

}

160

}

161

```

162

163

### Server Bootstrap

164

165

Manages RSocket server lifecycle within Spring Boot application context.

166

167

```java { .api }

168

/**

169

* Bootstrap component for RSocket server lifecycle management

170

*/

171

class RSocketServerBootstrap implements ApplicationEventPublisherAware, SmartLifecycle {

172

173

/**

174

* Creates server bootstrap with factory and socket acceptor

175

* @param serverFactory Factory for creating RSocket server instances

176

* @param socketAcceptor Handler for incoming RSocket connections

177

*/

178

RSocketServerBootstrap(RSocketServerFactory serverFactory, SocketAcceptor socketAcceptor);

179

180

/** Set application event publisher */

181

@Override

182

void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher);

183

184

/** Start the RSocket server */

185

@Override

186

void start();

187

188

/** Stop the RSocket server */

189

@Override

190

void stop();

191

192

/** Check if server is running */

193

@Override

194

boolean isRunning();

195

}

196

```

197

198

### Server Interface

199

200

Core RSocket server interface providing lifecycle management.

201

202

```java { .api }

203

/**

204

* Interface representing a fully configured RSocket server

205

*/

206

interface RSocketServer {

207

208

/**

209

* Start the RSocket server

210

* @throws RSocketServerException if server cannot be started

211

*/

212

void start() throws RSocketServerException;

213

214

/**

215

* Stop the RSocket server

216

* @throws RSocketServerException if server cannot be stopped

217

*/

218

void stop() throws RSocketServerException;

219

220

/**

221

* Get the address this server is listening on

222

* @return server bind address and port

223

*/

224

InetSocketAddress address();

225

}

226

227

/**

228

* Exception thrown during server operations

229

*/

230

class RSocketServerException extends RuntimeException {

231

RSocketServerException(String message, Throwable cause);

232

}

233

```

234

235

### WebSocket Integration

236

237

Integration with Spring WebFlux for RSocket over WebSocket endpoints.

238

239

```java { .api }

240

/**

241

* Route provider for WebSocket RSocket endpoints in WebFlux applications

242

*/

243

class RSocketWebSocketNettyRouteProvider implements NettyRouteProvider {

244

245

/**

246

* Creates WebSocket route provider

247

* @param mappingPath WebSocket endpoint path

248

* @param socketAcceptor Handler for RSocket connections

249

* @param customizers Server customizers

250

*/

251

RSocketWebSocketNettyRouteProvider(

252

String mappingPath,

253

SocketAcceptor socketAcceptor,

254

Stream<RSocketServerCustomizer> customizers

255

);

256

257

/**

258

* Configure WebSocket routes

259

* @param httpServerRoutes Existing HTTP routes to extend

260

* @return Updated routes with WebSocket RSocket endpoint

261

*/

262

@Override

263

HttpServerRoutes apply(HttpServerRoutes httpServerRoutes);

264

}

265

```

266

267

**WebSocket Integration Requirements:**

268

- Reactive web application (`WebApplicationType.REACTIVE`)

269

- WebSocket transport configured (`transport: websocket`)

270

- Mapping path specified (`mapping-path: "/rsocket"`)

271

- No standalone port configured (uses WebFlux server port)

272

273

**Example Configuration:**

274

275

```yaml

276

spring:

277

webflux:

278

base-path: /api

279

rsocket:

280

server:

281

transport: websocket

282

mapping-path: "/rsocket"

283

```

284

285

### Server Customization

286

287

Customize RSocket server configuration through the RSocketServerCustomizer interface.

288

289

```java { .api }

290

/**

291

* Callback interface for customizing RSocket servers

292

*/

293

@FunctionalInterface

294

interface RSocketServerCustomizer {

295

296

/**

297

* Customize the RSocket server configuration

298

* @param server RSocket server to customize

299

*/

300

void customize(RSocketServer server);

301

}

302

```

303

304

**Usage Examples:**

305

306

```java

307

@Component

308

public class ServerCustomizers {

309

310

// Enable zero-copy frame decoding for performance

311

@Bean

312

public RSocketServerCustomizer frameDecoderCustomizer() {

313

return server -> server.payloadDecoder(PayloadDecoder.ZERO_COPY);

314

}

315

316

// Configure connection handling

317

@Bean

318

public RSocketServerCustomizer connectionCustomizer() {

319

return server -> {

320

server.resume(Duration.ofMinutes(5));

321

server.lease(Leases::disabled);

322

};

323

}

324

325

// Add request interceptors

326

@Bean

327

public RSocketServerCustomizer interceptorCustomizer() {

328

return server -> {

329

server.interceptors(registry -> {

330

registry.forConnection(new LoggingConnectionInterceptor());

331

registry.forRequester(new MetricsRequesterInterceptor());

332

});

333

};

334

}

335

}

336

```

337

338

## Configuration Scenarios

339

340

### Scenario 1: Standalone TCP Server

341

342

```yaml

343

spring:

344

rsocket:

345

server:

346

port: 7878

347

transport: tcp

348

```

349

350

Creates dedicated RSocket server on port 7878 using TCP transport.

351

352

### Scenario 2: WebSocket with WebFlux

353

354

```yaml

355

server:

356

port: 8080

357

spring:

358

rsocket:

359

server:

360

transport: websocket

361

mapping-path: "/rsocket"

362

```

363

364

Adds RSocket WebSocket endpoint at `ws://localhost:8080/rsocket` to existing WebFlux server.

365

366

### Scenario 3: SSL-Enabled Server

367

368

```yaml

369

spring:

370

rsocket:

371

server:

372

port: 9443

373

transport: tcp

374

ssl:

375

enabled: true

376

key-store: file:server.p12

377

key-store-password: changeit

378

key-store-type: PKCS12

379

```

380

381

### Scenario 4: Custom Server Factory

382

383

```java

384

@Configuration

385

public class CustomServerConfig {

386

387

@Bean

388

@Primary

389

public RSocketServerFactory customFactory(ReactorResourceFactory resourceFactory) {

390

NettyRSocketServerFactory factory = new NettyRSocketServerFactory();

391

factory.setResourceFactory(resourceFactory);

392

factory.setTransport(RSocketServer.Transport.TCP);

393

factory.setFragmentSize(DataSize.ofKilobytes(128));

394

return factory;

395

}

396

}

397

```

398

399

## Events and Context

400

401

### Server Events

402

403

```java { .api }

404

/**

405

* Event published when RSocket server is initialized

406

*/

407

class RSocketServerInitializedEvent extends ApplicationEvent {

408

409

/**

410

* Get the initialized server instance

411

* @return RSocket server that was initialized

412

*/

413

RSocketServer getServer();

414

}

415

```

416

417

### Port Information

418

419

```java { .api }

420

/**

421

* Annotation for injecting local RSocket server port (deprecated)

422

* @deprecated since 2.7.0 for removal in 3.0.0

423

*/

424

@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE })

425

@Retention(RetentionPolicy.RUNTIME)

426

@Documented

427

@Value("${local.rsocket.server.port}")

428

@Deprecated

429

@interface LocalRSocketServerPort {

430

}

431

432

/**

433

* Test annotation for injecting local RSocket server port (replacement)

434

* @since 2.7.0

435

*/

436

@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE })

437

@Retention(RetentionPolicy.RUNTIME)

438

@Documented

439

@Value("${local.rsocket.server.port}")

440

@interface org.springframework.boot.test.rsocket.server.LocalRSocketServerPort {

441

}

442

```

443

444

**Usage Example:**

445

446

```java

447

@Component

448

public class ServerPortAware {

449

450

@LocalRSocketServerPort

451

private int rSocketPort;

452

453

@EventListener

454

public void onServerInitialized(RSocketServerInitializedEvent event) {

455

log.info("RSocket server started on port: {}", rSocketPort);

456

log.info("Server address: {}", event.getServer().address());

457

}

458

}

459

```