diff --git a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/Binding.java b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/Binding.java index 7096e5f44..380ca38e4 100644 --- a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/Binding.java +++ b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/Binding.java @@ -92,14 +92,25 @@ public interface Binding extends Pausable { } /** - * Returns the name of this binding (i.e., channel name) + * Returns the name of the destination for this binding * - * @return binding name + * @return destination name */ default String getName() { return null; } + /** + * Returns the name of the target for this binding (i.e., channel name) + * + * @return binding name + * + * @since 2.2 + */ + default String getBindingName() { + return null; + } + /** * Unbinds the target component represented by this instance and stops any active * components. Implementations must be idempotent. After this method is invoked, the diff --git a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/DefaultBinding.java b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/DefaultBinding.java index 7d71f4238..8dd989aa0 100644 --- a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/DefaultBinding.java +++ b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/DefaultBinding.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-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. @@ -23,6 +23,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.context.Lifecycle; +import org.springframework.integration.context.IntegrationObjectSupport; import org.springframework.integration.endpoint.Pausable; import org.springframework.integration.support.context.NamedComponent; import org.springframework.util.Assert; @@ -39,7 +40,7 @@ import org.springframework.util.StringUtils; * * @see org.springframework.cloud.stream.annotation.EnableBinding */ -@JsonPropertyOrder({ "name", "group", "pausable", "state"}) +@JsonPropertyOrder({ "name", "bindingName", "group", "pausable", "state"}) @JsonIgnoreProperties("running") public class DefaultBinding implements Binding { @@ -84,6 +85,12 @@ public class DefaultBinding implements Binding { return this.name; } + public String getBindingName() { + String resolvedName = (this.target instanceof IntegrationObjectSupport) + ? ((IntegrationObjectSupport)this.target).getComponentName() : getName(); + return resolvedName == null ? getName() : resolvedName; + } + public String getGroup() { return this.group; } diff --git a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/endpoint/BindingsEndpoint.java b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/endpoint/BindingsEndpoint.java index c22893140..da5607bb8 100644 --- a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/endpoint/BindingsEndpoint.java +++ b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/endpoint/BindingsEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2018 the original author or authors. + * Copyright 2018-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. @@ -116,10 +116,10 @@ public class BindingsEndpoint { return outputBindings; } - private Binding locateBinding(String name) { + private Binding locateBinding(String bindingName) { Stream> bindings = Stream.concat(this.gatherInputBindings().stream(), this.gatherOutputBindings().stream()); return bindings - .filter(binding -> name.equals(binding.getName())) + .filter(binding -> bindingName.equals(binding.getBindingName())) .findFirst() .orElse(null); }