diff --git a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/RemoteApplicationEvent.java b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/RemoteApplicationEvent.java index 98f2846..ce658a5 100644 --- a/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/RemoteApplicationEvent.java +++ b/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/RemoteApplicationEvent.java @@ -30,12 +30,16 @@ public abstract class RemoteApplicationEvent extends ApplicationEvent { super(source); this.originService = originService; if (destinationService == null) { - destinationService = "*"; + destinationService = "**"; } - if (StringUtils.countOccurrencesOf(destinationService, ":") <= 1 - && !destinationService.contains("*")) { - // All instances of the destination unless specifically requested - destinationService = destinationService + ":**"; + // If the destinationService is not already a wildcard, match everything that follows + // if there at most two path elements, and last element is not a global wildcard already + if (!"**".equals(destinationService)) { + if (StringUtils.countOccurrencesOf(destinationService, ":") <= 1 + && !StringUtils.endsWithIgnoreCase(destinationService, ":**")) { + // All instances of the destination unless specifically requested + destinationService = destinationService + ":**"; + } } this.destinationService = destinationService; this.id = UUID.randomUUID().toString(); diff --git a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/ServiceMatcherTests.java b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/ServiceMatcherTests.java index 60fb199..7ccf23a 100644 --- a/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/ServiceMatcherTests.java +++ b/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/ServiceMatcherTests.java @@ -71,6 +71,51 @@ public class ServiceMatcherTests { is(true)); } + @Test + public void forSelfWithGlobalWildcard() { + assertThat( + matcher.isForSelf( + new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", + "**", Collections.emptyMap())), + is(true)); + } + + @Test + public void forSelfWithWildcardName() { + assertThat( + matcher.isForSelf( + new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", + "o*", Collections.emptyMap())), + is(true)); + } + + @Test + public void forSelfWithWildcardNameAndProfile() { + assertThat( + matcher.isForSelf( + new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", + "o*:t*", Collections.emptyMap())), + is(true)); + } + + @Test + public void forSelfWithWildcardString() { + assertThat( + matcher.isForSelf( + new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", + "o*", Collections.emptyMap())), + is(true)); + } + + @Test + public void notForSelfWithWildCardNameAndMismatchingProfile() { + assertThat( + matcher.isForSelf( + new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", + "o*:f*", Collections.emptyMap())), + is(false)); + } + @Test public void forSelfWithDoubleWildcard() { assertThat(