Skip to content

Add initial support for RSockets #2902

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 25, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ project('spring-integration-rmi') {
}

project('spring-integration-rsocket') {
description = 'Spring Integration RSockets Support'
description = 'Spring Integration RSocket Support'
dependencies {
compile project(":spring-integration-core")
compile("io.projectreactor.netty:reactor-netty:$reactorNettyVersion")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.springframework.integration.expression.ExpressionUtils;
import org.springframework.integration.expression.ValueExpression;
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.rsocket.RSocketRequester;
import org.springframework.messaging.rsocket.RSocketStrategies;
Expand Down Expand Up @@ -57,11 +56,9 @@ public class RSocketOutboundGateway extends AbstractReplyProducingMessageHandler

private MimeType dataMimeType = MimeTypeUtils.TEXT_PLAIN;

@Nullable
private Consumer<RSocketFactory.ClientRSocketFactory> factoryConfigurer;
private Consumer<RSocketFactory.ClientRSocketFactory> factoryConfigurer = (clientRSocketFactory) -> { };

@Nullable
private Consumer<RSocketStrategies.Builder> strategiesConfigurer;
private Consumer<RSocketStrategies.Builder> strategiesConfigurer = (builder) -> { };

private Expression commandExpression = new ValueExpression<>(Command.requestResponse);

Expand Down Expand Up @@ -91,11 +88,13 @@ public void setDataMimeType(MimeType dataMimeType) {
this.dataMimeType = dataMimeType;
}

public void setFactoryConfigurer(@Nullable Consumer<RSocketFactory.ClientRSocketFactory> factoryConfigurer) {
public void setFactoryConfigurer(Consumer<RSocketFactory.ClientRSocketFactory> factoryConfigurer) {
Assert.notNull(factoryConfigurer, "'factoryConfigurer' must not be null");
this.factoryConfigurer = factoryConfigurer;
}

public void setStrategiesConfigurer(@Nullable Consumer<RSocketStrategies.Builder> strategiesConfigurer) {
public void setStrategiesConfigurer(Consumer<RSocketStrategies.Builder> strategiesConfigurer) {
Assert.notNull(strategiesConfigurer, "'strategiesConfigurer' must not be null");
this.strategiesConfigurer = strategiesConfigurer;
}

Expand Down Expand Up @@ -156,14 +155,11 @@ public void setExpectedResponseTypeExpression(Expression expectedResponseTypeExp
@Override
protected void doInit() {
super.doInit();
RSocketRequester.Builder builder = RSocketRequester.builder();
if (this.factoryConfigurer != null) {
builder.rsocketFactory(this.factoryConfigurer);
}
if (this.strategiesConfigurer != null) {
builder.rsocketStrategies(this.strategiesConfigurer);
}
this.rSocketRequesterMono = builder.connect(this.clientTransport, this.dataMimeType);
this.rSocketRequesterMono =
RSocketRequester.builder()
.rsocketFactory(this.factoryConfigurer)
.rsocketStrategies(this.strategiesConfigurer)
.connect(this.clientTransport, this.dataMimeType);

this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import org.springframework.stereotype.Controller;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.util.SocketUtils;

import io.netty.buffer.PooledByteBufAllocator;
import io.rsocket.RSocketFactory;
Expand All @@ -63,6 +62,7 @@
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.core.publisher.ReplayProcessor;
import reactor.netty.tcp.TcpServer;
import reactor.test.StepVerifier;

/**
Expand All @@ -74,7 +74,7 @@
@DirtiesContext
public class RSocketOutboundGatewayIntegrationTests {

private static final int PORT = SocketUtils.findAvailableTcpPort();
private static int PORT;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should no longer be static.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??? It is initialized from the static @BeforeAll and it won't be available in the ClientConfig below which has to be a static as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry; I meant it should no longer be upper case.


private static final String ROUTE_HEADER = "rsocket_route";

Expand All @@ -96,11 +96,13 @@ public class RSocketOutboundGatewayIntegrationTests {
@BeforeAll
static void setup() {
context = new AnnotationConfigApplicationContext(ServerConfig.class);

TcpServer tcpServer =
TcpServer.create().port(0)
.doOnBound(server -> PORT = server.port());
server = RSocketFactory.receive()
.frameDecoder(PayloadDecoder.ZERO_COPY)
.acceptor(context.getBean(MessageHandlerAcceptor.class))
.transport(TcpServerTransport.create("localhost", PORT))
.transport(TcpServerTransport.create(tcpServer))
.start()
.block();
}
Expand Down