diff --git a/core/spring-cloud-stream-integration-tests/src/test/java/org/springframework/cloud/stream/binding/BindingServiceTests.java b/core/spring-cloud-stream-integration-tests/src/test/java/org/springframework/cloud/stream/binding/BindingServiceTests.java index fa0abd885..2370d04be 100644 --- a/core/spring-cloud-stream-integration-tests/src/test/java/org/springframework/cloud/stream/binding/BindingServiceTests.java +++ b/core/spring-cloud-stream-integration-tests/src/test/java/org/springframework/cloud/stream/binding/BindingServiceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2023 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. @@ -89,6 +89,7 @@ import static org.mockito.Mockito.when; * @author Soby Chacko * @author Michael Michailidis * @author Chris Bono + * @author Artem Bilan */ public class BindingServiceTests { @@ -123,12 +124,12 @@ public class BindingServiceTests { @SuppressWarnings({ "unchecked", "rawtypes" }) @Test - void testMultipleConsumerBindings() throws Exception { + void testMultipleConsumerBindings() { BindingServiceProperties properties = new BindingServiceProperties(); Map bindingProperties = new HashMap<>(); BindingProperties props = new BindingProperties(); props.setDestination("foo,bar"); - final String inputChannelName = "input"; + String inputChannelName = "input"; bindingProperties.put(inputChannelName, props); properties.setBindings(bindingProperties); @@ -158,6 +159,8 @@ public class BindingServiceTests { assertThat(binding1).isSameAs(mockBinding1); assertThat(binding2).isSameAs(mockBinding2); + assertThat(service.getConsumerBindings("input")).containsSequence(bindings); + service.unbindConsumers("input"); verify(binder).bindConsumer(eq("foo"), isNull(), same(inputChannel), @@ -522,6 +525,9 @@ public class BindingServiceTests { delegate = TestUtils.getPropertyValue(binding, "delegate", Binding.class); } assertThat(delegate).isSameAs(mockBinding); + + assertThat(service.getProducerBinding("output")).isSameAs(binding); + service.unbindProducers(outputChannelName); verify(binder, times(2)).bindProducer(eq("foo"), same(outputChannel), any(ProducerProperties.class)); diff --git a/core/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binding/BindingService.java b/core/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binding/BindingService.java index c792a09bf..ffa70a6ac 100644 --- a/core/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binding/BindingService.java +++ b/core/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binding/BindingService.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2023 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. @@ -55,12 +55,13 @@ import org.springframework.validation.DataBinder; * @author Mark Fisher * @author Dave Syer * @author Marius Bogoevici - * @author Ilayaperumal Gopinathan` + * @author Ilayaperumal Gopinathan * @author Gary Russell * @author Janne Valkealahti * @author Soby Chacko * @author Michael Michailidis * @author Chris Bono + * @author Artem Bilan */ public class BindingService { @@ -320,10 +321,19 @@ public class BindingService { return this.producerBindings.keySet().toArray(new String[] {}); } + @Nullable + public Binding getProducerBinding(String bindingName) { + return this.producerBindings.get(bindingName); + } + public String[] getConsumerBindingNames() { return this.consumerBindings.keySet().toArray(new String[] {}); } + public List> getConsumerBindings(String bindingName) { + return this.consumerBindings.getOrDefault(bindingName, Collections.emptyList()); + } + public Binding doBindProducer(T output, String bindingTarget, Binder binder, ProducerProperties producerProperties) {