Skip to content

Commit 000632e

Browse files
artembilangaryrussell
authored andcommitted
Upgrade to Rsocket 1.0-RC7; fix deprecations
* Fix RSocket docs according new functionality **Cherry-pick to 5.2.x**
1 parent ceb1f65 commit 000632e

File tree

6 files changed

+78
-43
lines changed

6 files changed

+78
-43
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ ext {
8686
reactorVersion = 'Dysprosium-SR7'
8787
resilience4jVersion = '1.1.0'
8888
romeToolsVersion = '1.12.2'
89-
rsocketVersion = '1.0.0-RC6'
89+
rsocketVersion = '1.0.0-RC7'
9090
servletApiVersion = '4.0.1'
9191
smackVersion = '4.3.4'
9292
springAmqpVersion = project.hasProperty('springAmqpVersion') ? project.springAmqpVersion : '2.2.6.RELEASE'

spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/ClientRSocketConnector.java

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 the original author or authors.
2+
* Copyright 2019-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,11 +21,12 @@
2121
import java.util.LinkedHashMap;
2222
import java.util.Map;
2323

24-
import org.springframework.messaging.rsocket.ClientRSocketFactoryConfigurer;
24+
import org.springframework.messaging.rsocket.RSocketConnectorConfigurer;
2525
import org.springframework.messaging.rsocket.RSocketRequester;
2626
import org.springframework.util.Assert;
2727
import org.springframework.util.MimeType;
2828

29+
import io.rsocket.core.RSocketConnector;
2930
import io.rsocket.transport.ClientTransport;
3031
import io.rsocket.transport.netty.client.TcpClientTransport;
3132
import io.rsocket.transport.netty.client.WebsocketClientTransport;
@@ -48,7 +49,7 @@ public class ClientRSocketConnector extends AbstractRSocketConnector {
4849

4950
private final Map<Object, MimeType> setupMetadata = new LinkedHashMap<>(4);
5051

51-
private ClientRSocketFactoryConfigurer factoryConfigurer = (clientRSocketFactory) -> { };
52+
private RSocketConnectorConfigurer connectorConfigurer = (connector) -> { };
5253

5354
private Object setupData;
5455

@@ -92,18 +93,40 @@ public ClientRSocketConnector(ClientTransport clientTransport) {
9293

9394
/**
9495
* Callback to configure the {@code ClientRSocketFactory} directly.
95-
* Note: this class adds extra {@link ClientRSocketFactoryConfigurer} to the
96+
* Note: this class adds extra {@link org.springframework.messaging.rsocket.ClientRSocketFactoryConfigurer} to the
9697
* target {@link RSocketRequester} to populate a reference to an internal
9798
* {@link IntegrationRSocketMessageHandler#responder()}.
9899
* This overrides possible external
99100
* {@link io.rsocket.RSocketFactory.ClientRSocketFactory#acceptor(io.rsocket.SocketAcceptor)}
100-
* @param factoryConfigurer the {@link ClientRSocketFactoryConfigurer} to
101+
* @param factoryConfigurer the {@link org.springframework.messaging.rsocket.ClientRSocketFactoryConfigurer} to
101102
* configure the {@link io.rsocket.RSocketFactory.ClientRSocketFactory}.
102-
* @see RSocketRequester.Builder#rsocketFactory(ClientRSocketFactoryConfigurer)
103+
* @see RSocketRequester.Builder#rsocketFactory(org.springframework.messaging.rsocket.ClientRSocketFactoryConfigurer)
104+
* @deprecated since 5.2.6 in favor of {@link #setConnectorConfigurer(RSocketConnectorConfigurer)}
103105
*/
104-
public void setFactoryConfigurer(ClientRSocketFactoryConfigurer factoryConfigurer) {
106+
@Deprecated
107+
public void setFactoryConfigurer(
108+
org.springframework.messaging.rsocket.ClientRSocketFactoryConfigurer factoryConfigurer) {
109+
105110
Assert.notNull(factoryConfigurer, "'factoryConfigurer' must not be null");
106-
this.factoryConfigurer = factoryConfigurer;
111+
setConnectorConfigurer((connector) ->
112+
factoryConfigurer.configure(new io.rsocket.RSocketFactory.ClientRSocketFactory(connector)));
113+
}
114+
115+
/**
116+
* Callback to configure the {@code ClientRSocketFactory} directly.
117+
* Note: this class adds extra {@link RSocketConnectorConfigurer} to the
118+
* target {@link RSocketRequester} to populate a reference to an internal
119+
* {@link IntegrationRSocketMessageHandler#responder()}.
120+
* This overrides possible external
121+
* {@link RSocketConnector#acceptor(io.rsocket.SocketAcceptor)}
122+
* @param connectorConfigurer the {@link RSocketConnectorConfigurer} to
123+
* configure the {@link RSocketConnector}.
124+
* @since 5.2.6
125+
* @see RSocketRequester.Builder#rsocketConnector(RSocketConnectorConfigurer)
126+
*/
127+
public void setConnectorConfigurer(RSocketConnectorConfigurer connectorConfigurer) {
128+
Assert.notNull(connectorConfigurer, "'connectorConfigurer' must not be null");
129+
this.connectorConfigurer = connectorConfigurer;
107130
}
108131

109132
/**
@@ -160,9 +183,9 @@ public void afterPropertiesSet() {
160183
.rsocketStrategies(getRSocketStrategies())
161184
.setupData(this.setupData)
162185
.setupRoute(this.setupRoute, this.setupRouteVars)
163-
.rsocketFactory(this.factoryConfigurer)
164-
.rsocketFactory((rsocketFactory) ->
165-
rsocketFactory.acceptor(this.rSocketMessageHandler.responder()))
186+
.rsocketConnector(this.connectorConfigurer)
187+
.rsocketConnector((connector) ->
188+
connector.acceptor(this.rSocketMessageHandler.responder()))
166189
.apply((builder) -> this.setupMetadata.forEach(builder::setupMetadata))
167190
.connect(this.clientTransport)
168191
.cache();

spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/ServerRSocketConnector.java

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 the original author or authors.
2+
* Copyright 2019-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,7 +31,8 @@
3131
import org.springframework.util.Assert;
3232
import org.springframework.util.MimeType;
3333

34-
import io.rsocket.RSocketFactory;
34+
import io.rsocket.core.RSocketConnector;
35+
import io.rsocket.core.RSocketServer;
3536
import io.rsocket.transport.ServerTransport;
3637
import io.rsocket.transport.netty.server.CloseableChannel;
3738
import io.rsocket.transport.netty.server.TcpServerTransport;
@@ -47,13 +48,13 @@
4748
*
4849
* @since 5.2
4950
*
50-
* @see RSocketFactory.ServerRSocketFactory
51+
* @see RSocketConnector
5152
*/
5253
public class ServerRSocketConnector extends AbstractRSocketConnector implements ApplicationEventPublisherAware {
5354

5455
private final ServerTransport<CloseableChannel> serverTransport;
5556

56-
private Consumer<RSocketFactory.ServerRSocketFactory> factoryConfigurer = (serverRSocketFactory) -> { };
57+
private Consumer<RSocketServer> serverConfigurer = (rsocketServer) -> { };
5758

5859
private Mono<CloseableChannel> serverMono;
5960

@@ -104,12 +105,24 @@ private ServerRSocketMessageHandler serverRSocketMessageHandler() {
104105
}
105106

106107
/**
107-
* Provide a {@link Consumer} to configure the {@link RSocketFactory.ServerRSocketFactory}.
108-
* @param factoryConfigurer the {@link Consumer} to configure the {@link RSocketFactory.ServerRSocketFactory}.
108+
* Provide a {@link Consumer} to configure the {@link io.rsocket.RSocketFactory.ServerRSocketFactory}.
109+
* @param factoryConfigurer the {@link Consumer} to configure the {@link io.rsocket.RSocketFactory.ServerRSocketFactory}.
110+
* @deprecated since 5.2.6 in favor of {@link #setServerConfigurer(Consumer)}
109111
*/
110-
public void setFactoryConfigurer(Consumer<RSocketFactory.ServerRSocketFactory> factoryConfigurer) {
112+
@Deprecated
113+
public void setFactoryConfigurer(Consumer<io.rsocket.RSocketFactory.ServerRSocketFactory> factoryConfigurer) {
111114
Assert.notNull(factoryConfigurer, "'factoryConfigurer' must not be null");
112-
this.factoryConfigurer = factoryConfigurer;
115+
setServerConfigurer((server) ->
116+
factoryConfigurer.accept(new io.rsocket.RSocketFactory.ServerRSocketFactory(server)));
117+
}
118+
119+
/**
120+
* Provide a {@link Consumer} to configure the {@link RSocketServer}.
121+
* @param serverConfigurer the {@link Consumer} to configure the {@link RSocketServer}.
122+
* @since 5.2.6
123+
*/
124+
public void setServerConfigurer(Consumer<RSocketServer> serverConfigurer) {
125+
this.serverConfigurer = serverConfigurer;
113126
}
114127

115128
/**
@@ -164,14 +177,13 @@ public void setApplicationEventPublisher(ApplicationEventPublisher applicationEv
164177
public void afterPropertiesSet() {
165178
if (this.serverTransport != null) {
166179
super.afterPropertiesSet();
167-
RSocketFactory.ServerRSocketFactory serverFactory = RSocketFactory.receive();
168-
this.factoryConfigurer.accept(serverFactory);
180+
RSocketServer rsocketServer = RSocketServer.create();
181+
this.serverConfigurer.accept(rsocketServer);
169182

170183
this.serverMono =
171-
serverFactory
184+
rsocketServer
172185
.acceptor(serverRSocketMessageHandler().responder())
173-
.transport(this.serverTransport)
174-
.start()
186+
.bind(this.serverTransport)
175187
.cache();
176188
}
177189
}

spring-integration-rsocket/src/test/java/org/springframework/integration/rsocket/inbound/RSocketInboundGatewayIntegrationTests.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 the original author or authors.
2+
* Copyright 2019-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -44,7 +44,7 @@
4444
import org.springframework.test.annotation.DirtiesContext;
4545
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
4646

47-
import io.rsocket.RSocketFactory;
47+
import io.rsocket.core.RSocketServer;
4848
import io.rsocket.frame.decoder.PayloadDecoder;
4949
import io.rsocket.transport.netty.server.CloseableChannel;
5050
import io.rsocket.transport.netty.server.TcpServerTransport;
@@ -185,11 +185,10 @@ static class ServerConfig extends CommonConfig {
185185

186186
@Bean
187187
public CloseableChannel rsocketServer() {
188-
return RSocketFactory.receive()
189-
.frameDecoder(PayloadDecoder.ZERO_COPY)
188+
return RSocketServer.create()
189+
.payloadDecoder(PayloadDecoder.ZERO_COPY)
190190
.acceptor(serverRSocketMessageHandler().responder())
191-
.transport(TcpServerTransport.create("localhost", 0))
192-
.start()
191+
.bind(TcpServerTransport.create("localhost", 0))
193192
.block();
194193
}
195194

spring-integration-rsocket/src/test/java/org/springframework/integration/rsocket/outbound/RSocketOutboundGatewayIntegrationTests.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 the original author or authors.
2+
* Copyright 2019-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -59,7 +59,7 @@
5959
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
6060

6161
import io.rsocket.RSocket;
62-
import io.rsocket.RSocketFactory;
62+
import io.rsocket.core.RSocketServer;
6363
import io.rsocket.frame.decoder.PayloadDecoder;
6464
import io.rsocket.transport.netty.server.CloseableChannel;
6565
import io.rsocket.transport.netty.server.TcpServerTransport;
@@ -112,11 +112,10 @@ public class RSocketOutboundGatewayIntegrationTests {
112112
@BeforeAll
113113
static void setup() {
114114
serverContext = new AnnotationConfigApplicationContext(ServerConfig.class);
115-
server = RSocketFactory.receive()
116-
.frameDecoder(PayloadDecoder.ZERO_COPY)
115+
server = RSocketServer.create()
116+
.payloadDecoder(PayloadDecoder.ZERO_COPY)
117117
.acceptor(serverContext.getBean(RSocketMessageHandler.class).responder())
118-
.transport(TcpServerTransport.create("localhost", 0))
119-
.start()
118+
.bind(TcpServerTransport.create("localhost", 0))
120119
.block();
121120

122121
serverController = serverContext.getBean(TestController.class);
@@ -453,8 +452,8 @@ private void noMatchingRoute(MessageChannel inputChannel, FluxMessageChannel res
453452
.extracting(Message::getPayload)
454453
.isInstanceOf(MessageHandlingException.class)
455454
.satisfies((ex) -> assertThat((Exception) ex)
456-
.hasMessageContaining("io.rsocket.exceptions.ApplicationErrorException: " +
457-
"No handler for destination 'invalid'"));
455+
.hasMessageContaining(
456+
"ApplicationErrorException (0x201): No handler for destination 'invalid'"));
458457

459458
disposable.dispose();
460459
}
@@ -501,7 +500,9 @@ public static class ClientConfig extends CommonConfig {
501500
public RSocket rsocketForServerRequests() {
502501
return RSocketRequester.builder()
503502
.setupRoute("clientConnect")
504-
.rsocketFactory(RSocketMessageHandler.clientResponder(RSocketStrategies.create(), controller()))
503+
.rsocketConnector(connector ->
504+
connector.acceptor(
505+
RSocketMessageHandler.responder(RSocketStrategies.create(), controller())))
505506
.connectTcp("localhost", server.address().getPort())
506507
.block()
507508
.rsocket();

src/reference/asciidoc/rsocket.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Before starting an integration flow processing via channel adapters, we need to
3030
For this purpose, Spring Integration RSocket support provides the `ServerRSocketConnector` and `ClientRSocketConnector` implementations of the `AbstractRSocketConnector`.
3131

3232
The `ServerRSocketConnector` exposes a listener on the host and port according to provided `io.rsocket.transport.ServerTransport` for accepting connections from clients.
33-
An internal `RSocketFactory.ServerRSocketFactory` instance can be customized with the `setFactoryConfigurer()`, as well as other options that can be configured, e.g. `RSocketStrategies` and `MimeType` for payload data and headers metadata.
33+
An internal `RSocketServer` instance can be customized with the `setServerConfigurer()`, as well as other options that can be configured, e.g. `RSocketStrategies` and `MimeType` for payload data and headers metadata.
3434
When a `setupRoute` is provided from the client requester (see `ClientRSocketConnector` below), a connected client is stored as a `RSocketRequester` under the key determined by the `clientRSocketKeyStrategy` `BiFunction<Map<String, Object>, DataBuffer, Object>`.
3535
By default a connect data is used for the key as a converted value to string with UTF-8 charset.
3636
Such an `RSocketRequester` registry can be used in the application logic to determine a particular client connection for interaction with it, or for publishing the same message to all connected clients.
@@ -58,7 +58,7 @@ public ServerRSocketConnector serverRSocketConnector() {
5858
ServerRSocketConnector serverRSocketConnector = new ServerRSocketConnector("localhost", 0);
5959
serverRSocketConnector.setRSocketStrategies(rsocketStrategies());
6060
serverRSocketConnector.setMetadataMimeType(new MimeType("message", "x.rsocket.routing.v0"));
61-
serverRSocketConnector.setFactoryConfigurer((factory) -> factory.frameDecoder(PayloadDecoder.ZERO_COPY));
61+
serverRSocketConnector.setServerConfigurer((server) -> server.payloadDecoder(PayloadDecoder.ZERO_COPY));
6262
serverRSocketConnector.setClientRSocketKeyStrategy((headers, data) -> ""
6363
+ headers.get(DestinationPatternsMessageCondition.LOOKUP_DESTINATION_HEADER));
6464
return serverRSocketConnector;
@@ -80,7 +80,7 @@ In addition the `ServerRSocketMessageHandler` can be configured with a `messageM
8080
This can be useful in mixed configurations, when classic `@MessageMapping` methods are present in the same application along with RSocket channel adapters and an externally configured RSocket server is present in the application.
8181

8282
The `ClientRSocketConnector` serves as a holder for `RSocketRequester` based on the `RSocket` connected via the provided `ClientTransport`.
83-
The `RSocketFactory.ClientRSocketFactory` can be customized with the provided `ClientRSocketFactoryConfigurer`.
83+
The `RSocketConnector` can be customized with the provided `RSocketConnectorConfigurer`.
8484
The `setupRoute` (with optional templates variables) and `setupData` with metadata can be also configured on this component.
8585

8686
A typical client configuration might look like this:

0 commit comments

Comments
 (0)