diff --git a/pom.xml b/pom.xml index e4f083a..7f3602a 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,6 @@ spring-cloud-bus-dependencies spring-cloud-bus - spring-cloud-bus-rsocket spring-cloud-bus-tests spring-cloud-starter-bus-amqp spring-cloud-starter-bus-kafka diff --git a/spring-cloud-bus-dependencies/pom.xml b/spring-cloud-bus-dependencies/pom.xml index fac40c1..9ed6105 100644 --- a/spring-cloud-bus-dependencies/pom.xml +++ b/spring-cloud-bus-dependencies/pom.xml @@ -36,11 +36,6 @@ spring-cloud-bus ${project.version} - - org.springframework.cloud - spring-cloud-bus-rsocket - ${project.version} - diff --git a/spring-cloud-bus-rsocket/pom.xml b/spring-cloud-bus-rsocket/pom.xml deleted file mode 100644 index 02f298c..0000000 --- a/spring-cloud-bus-rsocket/pom.xml +++ /dev/null @@ -1,75 +0,0 @@ - - - 4.0.0 - - spring-cloud-bus-rsocket - jar - - spring-cloud-bus-rsocket - Spring Cloud Bus - - - org.springframework.cloud - spring-cloud-bus-parent - 5.0.0-SNAPSHOT - .. - - - - 0.2.0 - - - - - org.springframework.boot - spring-boot-configuration-processor - true - - - org.springframework.boot - spring-boot-starter-actuator - true - - - org.springframework.cloud - spring-cloud-bus - - - org.springframework.cloud - spring-cloud-function-rsocket - - - com.fasterxml.jackson.dataformat - jackson-dataformat-cbor - - - io.rsocket.routing - rsocket-routing-client-spring - ${rsocket-routing.version} - true - - - org.springframework.boot - spring-boot-autoconfigure-processor - true - - - org.springframework.boot - spring-boot-starter-test - test - - - org.junit.vintage - junit-vintage-engine - test - - - org.springframework.cloud - spring-cloud-test-support - test - - - - diff --git a/spring-cloud-bus-rsocket/src/main/java/org/springframework/cloud/bus/rsocket/BusRSocketAutoConfiguration.java b/spring-cloud-bus-rsocket/src/main/java/org/springframework/cloud/bus/rsocket/BusRSocketAutoConfiguration.java deleted file mode 100644 index 79f2fb4..0000000 --- a/spring-cloud-bus-rsocket/src/main/java/org/springframework/cloud/bus/rsocket/BusRSocketAutoConfiguration.java +++ /dev/null @@ -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); - } - -} diff --git a/spring-cloud-bus-rsocket/src/main/java/org/springframework/cloud/bus/rsocket/BusRSocketEnvironmentPostProcessor.java b/spring-cloud-bus-rsocket/src/main/java/org/springframework/cloud/bus/rsocket/BusRSocketEnvironmentPostProcessor.java deleted file mode 100644 index 51af6f8..0000000 --- a/spring-cloud-bus-rsocket/src/main/java/org/springframework/cloud/bus/rsocket/BusRSocketEnvironmentPostProcessor.java +++ /dev/null @@ -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 defaults = new HashMap<>(); - defaults.put(RoutingClientProperties.CONFIG_PREFIX + ".tags.bus", true); - addOrReplace(environment.getPropertySources(), defaults, DEFAULTS_PROPERTY_SOURCE_NAME, false); - } - -} diff --git a/spring-cloud-bus-rsocket/src/main/java/org/springframework/cloud/bus/rsocket/BusRSocketProperties.java b/spring-cloud-bus-rsocket/src/main/java/org/springframework/cloud/bus/rsocket/BusRSocketProperties.java deleted file mode 100644 index b183430..0000000 --- a/spring-cloud-bus-rsocket/src/main/java/org/springframework/cloud/bus/rsocket/BusRSocketProperties.java +++ /dev/null @@ -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 defaultTags = new LinkedHashMap<>(); - - @Override - public void afterPropertiesSet() { - if (CollectionUtils.isEmpty(defaultTags)) { - defaultTags.put(MutableKey.of("bus"), "true"); - } - } - - public Map getDefaultTags() { - return this.defaultTags; - } - - @Override - public String toString() { - return new ToStringCreator(this).append("defaultTags", defaultTags).toString(); - } - -} diff --git a/spring-cloud-bus-rsocket/src/main/java/org/springframework/cloud/bus/rsocket/RSocketRequesterBusBridge.java b/spring-cloud-bus-rsocket/src/main/java/org/springframework/cloud/bus/rsocket/RSocketRequesterBusBridge.java deleted file mode 100644 index c5ca8c7..0000000 --- a/spring-cloud-bus-rsocket/src/main/java/org/springframework/cloud/bus/rsocket/RSocketRequesterBusBridge.java +++ /dev/null @@ -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 getTagsFromDestination(String delimitedProperties) { - String[] properties = StringUtils.tokenizeToStringArray(delimitedProperties, ":"); - Map 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; - } - -} diff --git a/spring-cloud-bus-rsocket/src/main/java/org/springframework/cloud/bus/rsocket/RSocketServiceMatcher.java b/spring-cloud-bus-rsocket/src/main/java/org/springframework/cloud/bus/rsocket/RSocketServiceMatcher.java deleted file mode 100644 index 8944f37..0000000 --- a/spring-cloud-bus-rsocket/src/main/java/org/springframework/cloud/bus/rsocket/RSocketServiceMatcher.java +++ /dev/null @@ -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 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 tags = getTagsFromDestination(event.getDestinationService()); - for (Map.Entry 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; - } - -} diff --git a/spring-cloud-bus-rsocket/src/main/java/org/springframework/cloud/bus/rsocket/RoutingClientDestinationFactory.java b/spring-cloud-bus-rsocket/src/main/java/org/springframework/cloud/bus/rsocket/RoutingClientDestinationFactory.java deleted file mode 100644 index 432e7c0..0000000 --- a/spring-cloud-bus-rsocket/src/main/java/org/springframework/cloud/bus/rsocket/RoutingClientDestinationFactory.java +++ /dev/null @@ -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 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; - }; - } - -} diff --git a/spring-cloud-bus-rsocket/src/main/resources/META-INF/spring.factories b/spring-cloud-bus-rsocket/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 0d36dfe..0000000 --- a/spring-cloud-bus-rsocket/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,3 +0,0 @@ -# Environment Post Processor -org.springframework.boot.env.EnvironmentPostProcessor=\ -org.springframework.cloud.bus.rsocket.BusRSocketEnvironmentPostProcessor diff --git a/spring-cloud-bus-rsocket/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/spring-cloud-bus-rsocket/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports deleted file mode 100644 index 91a5ae7..0000000 --- a/spring-cloud-bus-rsocket/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ /dev/null @@ -1 +0,0 @@ -org.springframework.cloud.bus.rsocket.BusRSocketAutoConfiguration