Creates RSocketRoutingAutoConfiguration.
Moves rsocket-routing-client-spring to an optional dependency.
This commit is contained in:
@@ -19,14 +19,11 @@ package org.springframework.cloud.function.rsocket;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
import io.rsocket.RSocket;
|
||||
import io.rsocket.SocketAcceptor;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.function.context.FunctionCatalog;
|
||||
@@ -41,7 +38,6 @@ import org.springframework.context.SmartLifecycle;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.messaging.rsocket.RSocketConnectorConfigurer;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -55,7 +51,6 @@ import org.springframework.util.StringUtils;
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@EnableConfigurationProperties({ FunctionProperties.class, RSocketFunctionProperties.class })
|
||||
@ConditionalOnProperty(name = FunctionProperties.PREFIX + ".rsocket.enabled", matchIfMissing = true)
|
||||
@AutoConfigureBefore(name = "io.rsocket.routing.client.spring.RoutingClientAutoConfiguration")
|
||||
public class RSocketAutoConfiguration {
|
||||
|
||||
private static Log logger = LogFactory.getLog(RSocketAutoConfiguration.class);
|
||||
@@ -66,18 +61,10 @@ public class RSocketAutoConfiguration {
|
||||
return new FunctionToRSocketBinder(functionCatalog, functionProperties, rSocketFunctionProperties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnClass(name = "io.rsocket.routing.client.spring.RoutingClientAutoConfiguration")
|
||||
//TODO: move to broker specific auto config
|
||||
public RSocketConnectorConfigurer functionRSocketConnectorConfigurer(
|
||||
FunctionToRSocketBinder binder) {
|
||||
return connector -> connector.acceptor(SocketAcceptor.with(binder.getRSocket()));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static class FunctionToRSocketBinder implements InitializingBean, ApplicationContextAware, SmartLifecycle {
|
||||
static class FunctionToRSocketBinder implements InitializingBean, ApplicationContextAware, SmartLifecycle {
|
||||
|
||||
private final FunctionCatalog functionCatalog;
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2020-2020 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.function.rsocket;
|
||||
|
||||
import io.rsocket.SocketAcceptor;
|
||||
import io.rsocket.routing.client.spring.RoutingClientAutoConfiguration;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.cloud.function.context.FunctionProperties;
|
||||
import org.springframework.cloud.function.rsocket.RSocketAutoConfiguration.FunctionToRSocketBinder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.messaging.rsocket.RSocketConnectorConfigurer;
|
||||
|
||||
/**
|
||||
* Configuration for components required to support RSocket Routing Client
|
||||
* integration with spring-cloud-function.
|
||||
*
|
||||
* @author Spencer Gibb
|
||||
* @since 3.1
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnClass(RoutingClientAutoConfiguration.class)
|
||||
@ConditionalOnProperty(name = FunctionProperties.PREFIX + ".rsocket.enabled", matchIfMissing = true)
|
||||
@AutoConfigureBefore(RoutingClientAutoConfiguration.class)
|
||||
@AutoConfigureAfter(RSocketAutoConfiguration.class)
|
||||
public class RSocketRoutingAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public RSocketConnectorConfigurer functionRSocketConnectorConfigurer(
|
||||
FunctionToRSocketBinder binder) {
|
||||
return connector -> connector.acceptor(SocketAcceptor.with(binder.getRSocket()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1 +1,3 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=org.springframework.cloud.function.rsocket.RSocketAutoConfiguration
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
org.springframework.cloud.function.rsocket.RSocketAutoConfiguration,\
|
||||
org.springframework.cloud.function.rsocket.RSocketRoutingAutoConfiguration
|
||||
|
||||
Reference in New Issue
Block a user