Skip to content

Provide an RSocketMessageHandlerCustomizer to allow customizing of the RSocketMessageHandler #21081

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

Closed
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.springframework.boot.autoconfigure.rsocket;

import org.apache.catalina.connector.Connector;
import org.springframework.boot.web.embedded.tomcat.ConfigurableTomcatWebServerFactory;
import org.springframework.messaging.rsocket.RSocketStrategies;
import org.springframework.messaging.rsocket.annotation.support.RSocketMessageHandler;
import org.springframework.util.RouteMatcher;

/**
* @author Aarti Gupta
* Callback interface that can be used to customize a RSocketMessageHandler {@link Connector}.
*/
@FunctionalInterface
public interface RSocketMessageHandlerCustomizer {

RSocketMessageHandler setRouteMatcher(RouteMatcher handler);
Copy link
Contributor

Choose a reason for hiding this comment

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

To be consistent with other customizers, the method shouldn't return anything but be void instead.


}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import io.rsocket.RSocketFactory;
import io.rsocket.transport.netty.server.TcpServerTransport;

import java.util.Objects;
import java.util.stream.Collectors;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
Expand All @@ -28,6 +31,7 @@
import org.springframework.messaging.rsocket.RSocketRequester;
import org.springframework.messaging.rsocket.RSocketStrategies;
import org.springframework.messaging.rsocket.annotation.support.RSocketMessageHandler;
import org.springframework.util.RouteMatcher;

/**
* {@link EnableAutoConfiguration Auto-configuration} for Spring RSocket support in Spring
Expand All @@ -36,17 +40,19 @@
* @author Brian Clozel
* @since 2.2.0
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({ RSocketRequester.class, RSocketFactory.class, TcpServerTransport.class })
@Configuration(proxyBeanMethods = true)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason this was change to true?

@ConditionalOnClass({RSocketRequester.class, RSocketFactory.class, TcpServerTransport.class})
@AutoConfigureAfter(RSocketStrategiesAutoConfiguration.class)
public class RSocketMessagingAutoConfiguration {


@Bean
@ConditionalOnMissingBean
public RSocketMessageHandler messageHandler(RSocketStrategies rSocketStrategies) {
RSocketMessageHandler messageHandler = new RSocketMessageHandler();
messageHandler.setRSocketStrategies(rSocketStrategies);
return messageHandler;
@ConditionalOnMissingBean(RSocketMessageHandler.class)
public RSocketMessageHandler messageHandler(RSocketStrategies rSocketStrategies, ObjectProvider<RSocketMessageHandlerCustomizer> customizers) {
RSocketMessageHandlerCustomizer rSocketMessageHandlerCustomizer = customizers.getIfAvailable();
return rSocketMessageHandlerCustomizer.setRouteMatcher(rSocketStrategies.routeMatcher());
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like messageHandler.setRSocketStrategies(rSocketStrategies) got removed as part of this change. We still want to do that and apply the customizers after that.

}



}