Remove RSocket support
Fixes gh-271
This commit is contained in:
1
pom.xml
1
pom.xml
@@ -21,7 +21,6 @@
|
||||
<modules>
|
||||
<module>spring-cloud-bus-dependencies</module>
|
||||
<module>spring-cloud-bus</module>
|
||||
<module>spring-cloud-bus-rsocket</module>
|
||||
<module>spring-cloud-bus-tests</module>
|
||||
<module>spring-cloud-starter-bus-amqp</module>
|
||||
<module>spring-cloud-starter-bus-kafka</module>
|
||||
|
||||
@@ -36,11 +36,6 @@
|
||||
<artifactId>spring-cloud-bus</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-bus-rsocket</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<profiles>
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>spring-cloud-bus-rsocket</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>spring-cloud-bus-rsocket</name>
|
||||
<description>Spring Cloud Bus</description>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-bus-parent</artifactId>
|
||||
<version>5.0.0-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<rsocket-routing.version>0.2.0</rsocket-routing.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-bus</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-function-rsocket</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-cbor</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.rsocket.routing</groupId>
|
||||
<artifactId>rsocket-routing-client-spring</artifactId>
|
||||
<version>${rsocket-routing.version}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-autoconfigure-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-test-support</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-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.bus.rsocket;
|
||||
|
||||
import io.rsocket.RSocket;
|
||||
import io.rsocket.routing.client.spring.RoutingClientProperties;
|
||||
import io.rsocket.routing.client.spring.RoutingRSocketRequester;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.bus.BusAutoConfiguration;
|
||||
import org.springframework.cloud.bus.BusProperties;
|
||||
import org.springframework.cloud.bus.BusRefreshAutoConfiguration;
|
||||
import org.springframework.cloud.bus.BusShutdownAutoConfiguration;
|
||||
import org.springframework.cloud.bus.ConditionalOnBusEnabled;
|
||||
import org.springframework.cloud.bus.PathServiceMatcherAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnBusEnabled
|
||||
@EnableConfigurationProperties(BusRSocketProperties.class)
|
||||
@ConditionalOnClass({ RSocket.class, RoutingRSocketRequester.class })
|
||||
@AutoConfigureBefore({ BusAutoConfiguration.class, BusRefreshAutoConfiguration.class,
|
||||
PathServiceMatcherAutoConfiguration.class, BusShutdownAutoConfiguration.class })
|
||||
public class BusRSocketAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public RoutingClientDestinationFactory routingClientDestinationFactory(BusRSocketProperties properties) {
|
||||
return new RoutingClientDestinationFactory(properties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RSocketRequesterBusBridge rSocketRequesterBusBridge(RoutingRSocketRequester requester) {
|
||||
return new RSocketRequesterBusBridge(requester);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RSocketServiceMatcher rSocketServiceMatcher(BusProperties properties,
|
||||
RoutingClientProperties routingClientProperties) {
|
||||
return new RSocketServiceMatcher(properties.getId(), routingClientProperties);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.bus.rsocket;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import io.rsocket.routing.client.spring.RoutingClientProperties;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.env.EnvironmentPostProcessor;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
|
||||
import static org.springframework.cloud.bus.BusEnvironmentPostProcessor.addOrReplace;
|
||||
|
||||
/**
|
||||
* {@link EnvironmentPostProcessor} that sets the default properties for the RSocket
|
||||
* Routing Client.
|
||||
*/
|
||||
public class BusRSocketEnvironmentPostProcessor implements EnvironmentPostProcessor {
|
||||
|
||||
static final String DEFAULTS_PROPERTY_SOURCE_NAME = "springCloudBusRSocketDefaultProperties";
|
||||
|
||||
@Override
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
|
||||
Map<String, Object> defaults = new HashMap<>();
|
||||
defaults.put(RoutingClientProperties.CONFIG_PREFIX + ".tags.bus", true);
|
||||
addOrReplace(environment.getPropertySources(), defaults, DEFAULTS_PROPERTY_SOURCE_NAME, false);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-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.bus.rsocket;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import io.rsocket.routing.common.MutableKey;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.core.style.ToStringCreator;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
@ConfigurationProperties("spring.cloud.bus.rsocket")
|
||||
public class BusRSocketProperties implements InitializingBean {
|
||||
|
||||
private final Map<MutableKey, String> defaultTags = new LinkedHashMap<>();
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
if (CollectionUtils.isEmpty(defaultTags)) {
|
||||
defaultTags.put(MutableKey.of("bus"), "true");
|
||||
}
|
||||
}
|
||||
|
||||
public Map<MutableKey, String> getDefaultTags() {
|
||||
return this.defaultTags;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringCreator(this).append("defaultTags", defaultTags).toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-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.bus.rsocket;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import io.rsocket.routing.client.spring.RoutingRSocketRequester;
|
||||
import io.rsocket.routing.common.Key;
|
||||
import io.rsocket.routing.common.WellKnownKey;
|
||||
import io.rsocket.routing.frames.RoutingType;
|
||||
|
||||
import org.springframework.cloud.bus.BusBridge;
|
||||
import org.springframework.cloud.bus.BusConstants;
|
||||
import org.springframework.cloud.bus.event.RemoteApplicationEvent;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
public class RSocketRequesterBusBridge implements BusBridge {
|
||||
|
||||
public RSocketRequesterBusBridge(RoutingRSocketRequester requester) {
|
||||
this.requester = requester;
|
||||
}
|
||||
|
||||
private final RoutingRSocketRequester requester;
|
||||
|
||||
@Override
|
||||
public void send(RemoteApplicationEvent event) {
|
||||
requester.route(BusConstants.BUS_CONSUMER).address(builder -> {
|
||||
builder.routingType(RoutingType.MULTICAST);
|
||||
// get tags out of destination
|
||||
getTagsFromDestination(event.getDestinationService()).forEach(builder::with);
|
||||
}).data(event).send().subscribe();
|
||||
}
|
||||
|
||||
static Map<Key, String> getTagsFromDestination(String delimitedProperties) {
|
||||
String[] properties = StringUtils.tokenizeToStringArray(delimitedProperties, ":");
|
||||
Map<Key, String> map = new HashMap<>();
|
||||
for (String property : properties) {
|
||||
int index = lowestIndexOf(property, "=");
|
||||
String key = (index > 0) ? property.substring(0, index) : property;
|
||||
String value = (index > 0) ? property.substring(index + 1) : null;
|
||||
|
||||
try {
|
||||
WellKnownKey wellKnownKey = WellKnownKey.valueOf(key);
|
||||
map.put(Key.of(wellKnownKey), value);
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
try {
|
||||
WellKnownKey wellKnownKey = WellKnownKey.valueOf(key.toUpperCase(Locale.ROOT));
|
||||
map.put(Key.of(wellKnownKey), value);
|
||||
}
|
||||
catch (IllegalArgumentException e2) {
|
||||
// not a WellKnownKey, use string
|
||||
map.put(Key.of(key), value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private static int lowestIndexOf(String property, String... candidates) {
|
||||
int index = -1;
|
||||
for (String candidate : candidates) {
|
||||
int candidateIndex = property.indexOf(candidate);
|
||||
if (candidateIndex > 0) {
|
||||
index = (index != -1) ? Math.min(index, candidateIndex) : candidateIndex;
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-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.bus.rsocket;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import io.rsocket.routing.client.spring.RoutingClientProperties;
|
||||
import io.rsocket.routing.common.Key;
|
||||
import io.rsocket.routing.common.WellKnownKey;
|
||||
|
||||
import org.springframework.cloud.bus.ServiceMatcher;
|
||||
import org.springframework.cloud.bus.event.RemoteApplicationEvent;
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
|
||||
import static org.springframework.cloud.bus.rsocket.RSocketRequesterBusBridge.getTagsFromDestination;
|
||||
|
||||
/**
|
||||
* A pass thru patcher that allows the RSocket Routing broker to determine which instances
|
||||
* to send to.
|
||||
*/
|
||||
public class RSocketServiceMatcher implements ServiceMatcher {
|
||||
|
||||
private final String busId;
|
||||
|
||||
private final RoutingClientProperties properties;
|
||||
|
||||
private final AntPathMatcher antPathMatcher = new AntPathMatcher();
|
||||
|
||||
private final Map<Key, String> localTags = new HashMap<>();
|
||||
|
||||
public RSocketServiceMatcher(String busId, RoutingClientProperties properties) {
|
||||
this.busId = busId;
|
||||
this.properties = properties;
|
||||
convertLocalTags(properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFromSelf(RemoteApplicationEvent event) {
|
||||
String originService = event.getOriginService();
|
||||
String serviceId = getBusId();
|
||||
return antPathMatcher.match(originService, serviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isForSelf(RemoteApplicationEvent event) {
|
||||
Map<Key, String> tags = getTagsFromDestination(event.getDestinationService());
|
||||
for (Map.Entry<Key, String> entry : tags.entrySet()) {
|
||||
String existingValue = localTags.get(entry.getKey());
|
||||
if (existingValue == null || !existingValue.equals(entry.getValue())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void convertLocalTags(RoutingClientProperties properties) {
|
||||
properties.getTags().forEach((key, value) -> {
|
||||
if (key.getWellKnownKey() != null) {
|
||||
localTags.put(Key.of(key.getWellKnownKey()), value);
|
||||
}
|
||||
else {
|
||||
localTags.put(Key.of(key.getKey()), value);
|
||||
}
|
||||
});
|
||||
localTags.put(Key.of(WellKnownKey.SERVICE_NAME), properties.getServiceName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBusId() {
|
||||
return busId;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-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.bus.rsocket;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.springframework.cloud.bus.event.Destination;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
public class RoutingClientDestinationFactory implements Destination.Factory {
|
||||
|
||||
private final BusRSocketProperties properties;
|
||||
|
||||
public RoutingClientDestinationFactory(BusRSocketProperties properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Destination getDestination(String originalDestination) {
|
||||
ArrayList<String> entries = new ArrayList<>();
|
||||
properties.getDefaultTags().forEach((key, s) -> {
|
||||
String keyStr = (key.getWellKnownKey() != null) ? key.getWellKnownKey().name() : key.getKey();
|
||||
entries.add(keyStr + "=" + s);
|
||||
});
|
||||
String defaultTags = StringUtils.collectionToDelimitedString(entries, ":");
|
||||
return () -> {
|
||||
String destination = (ObjectUtils.isEmpty(originalDestination)) ? defaultTags
|
||||
: defaultTags + ":" + originalDestination;
|
||||
if (ObjectUtils.isEmpty(destination)) {
|
||||
throw new IllegalArgumentException("destination may not be empty");
|
||||
}
|
||||
return destination;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
# Environment Post Processor
|
||||
org.springframework.boot.env.EnvironmentPostProcessor=\
|
||||
org.springframework.cloud.bus.rsocket.BusRSocketEnvironmentPostProcessor
|
||||
@@ -1 +0,0 @@
|
||||
org.springframework.cloud.bus.rsocket.BusRSocketAutoConfiguration
|
||||
Reference in New Issue
Block a user