From 6b4efcce11260a8edba6c6325954bfb8c9e40965 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Mon, 31 May 2021 14:44:15 +0200 Subject: [PATCH] Polish "Apply RSocketConnectorConfigurer beans to RSocketRequester.Builder" See gh-26341 --- .../rsocket/RSocketRequesterAutoConfiguration.java | 10 +++++----- .../RSocketRequesterAutoConfigurationTests.java | 10 ++++------ .../src/docs/asciidoc/features/rsocket.adoc | 2 +- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/rsocket/RSocketRequesterAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/rsocket/RSocketRequesterAutoConfiguration.java index 9cabe26cd4b..f9987d9f8b8 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/rsocket/RSocketRequesterAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/rsocket/RSocketRequesterAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Scope; import org.springframework.messaging.rsocket.RSocketConnectorConfigurer; import org.springframework.messaging.rsocket.RSocketRequester; +import org.springframework.messaging.rsocket.RSocketRequester.Builder; import org.springframework.messaging.rsocket.RSocketStrategies; /** @@ -39,7 +40,6 @@ import org.springframework.messaging.rsocket.RSocketStrategies; * requester instances with different configurations. * * @author Brian Clozel - * @author Nguyen Bao Sach * @since 2.2.0 */ @Configuration(proxyBeanMethods = false) @@ -52,9 +52,9 @@ public class RSocketRequesterAutoConfiguration { @ConditionalOnMissingBean public RSocketRequester.Builder rSocketRequesterBuilder(RSocketStrategies strategies, ObjectProvider connectorConfigurers) { - return connectorConfigurers.orderedStream() - .collect(RSocketRequester::builder, RSocketRequester.Builder::rsocketConnector, (first, second) -> { - }).rsocketStrategies(strategies); + Builder builder = RSocketRequester.builder().rsocketStrategies(strategies); + connectorConfigurers.orderedStream().forEach(builder::rsocketConnector); + return builder; } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/rsocket/RSocketRequesterAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/rsocket/RSocketRequesterAutoConfigurationTests.java index a42304e47e1..46971f1e490 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/rsocket/RSocketRequesterAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/rsocket/RSocketRequesterAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -64,14 +64,12 @@ class RSocketRequesterAutoConfigurationTests { } @Test - void rSocketConnectorConfigurersArePickedUp() { + void shouldCreateBuilderWithAvailableRSocketConnectorConfigurers() { RSocketConnectorConfigurer first = mock(RSocketConnectorConfigurer.class); RSocketConnectorConfigurer second = mock(RSocketConnectorConfigurer.class); - this.contextRunner.withBean("firstRSocketConnectorConfigurer", RSocketConnectorConfigurer.class, () -> first) - .withBean("secondRSocketConnectorConfigurer", RSocketConnectorConfigurer.class, () -> second) - .run((context) -> { + this.contextRunner.withBean("first", RSocketConnectorConfigurer.class, () -> first) + .withBean("second", RSocketConnectorConfigurer.class, () -> second).run((context) -> { assertThat(context).getBeans(RSocketConnectorConfigurer.class).hasSize(2); - RSocketRequester.Builder builder = context.getBean(RSocketRequester.Builder.class); assertThat(builder).extracting("rsocketConnectorConfigurers", as(InstanceOfAssertFactories.LIST)) .containsExactly(first, second); diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/rsocket.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/rsocket.adoc index 8318b8faf1e..16ad8315e57 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/rsocket.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/rsocket.adoc @@ -73,7 +73,7 @@ Once the `RSocket` channel is established between server and client, any party c As a server, you can get injected with an `RSocketRequester` instance on any handler method of an RSocket `@Controller`. As a client, you need to configure and establish an RSocket connection first. -Spring Boot auto-configures an `RSocketRequester.Builder` for such cases with the expected codecs. +Spring Boot auto-configures an `RSocketRequester.Builder` for such cases with the expected codecs and apply any `RSocketConnectorConfigurer` bean. The `RSocketRequester.Builder` instance is a prototype bean, meaning each injection point will provide you with a new instance . This is done on purpose since this builder is stateful and you shouldn't create requesters with different setups using the same instance.