From fd989cd712313ad62a8403b52a1a67d7ee9122d3 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Tue, 11 Dec 2018 19:45:44 +0100 Subject: [PATCH] GH-1553 Fixed inconsistencies in function bootstrap Resolves #1553 --- .../binder/AbstractMessageChannelBinder.java | 42 ++++++++++++---- .../function/FunctionConfiguration.java | 50 +++++++++++++++---- .../IntegrationFlowFunctionSupport.java | 23 ++++++++- .../SourceToFunctionsSupportTests.java | 8 --- 4 files changed, 95 insertions(+), 28 deletions(-) diff --git a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/AbstractMessageChannelBinder.java b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/AbstractMessageChannelBinder.java index fca8bbd82..e047d9dce 100644 --- a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/AbstractMessageChannelBinder.java +++ b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/AbstractMessageChannelBinder.java @@ -51,6 +51,7 @@ import org.springframework.integration.channel.PublishSubscribeChannel; import org.springframework.integration.context.IntegrationContextUtils; import org.springframework.integration.core.MessageProducer; import org.springframework.integration.core.MessageSource; +import org.springframework.integration.dsl.IntegrationFlow; import org.springframework.integration.dsl.IntegrationFlowBuilder; import org.springframework.integration.dsl.IntegrationFlows; import org.springframework.integration.handler.AbstractMessageHandler; @@ -119,6 +120,9 @@ public abstract class AbstractMessageChannelBinder publisher = MessageChannelReactiveUtils.toPublisher(outputChannel); @@ -846,22 +863,25 @@ public abstract class AbstractMessageChannelBinder IntegrationFlowBuilder integrationFlowForFunction(SubscribableChannel inputChannel, MessageChannel outputChannel) { + + if (inputChannel instanceof IntegrationObjectSupport) { + String inputBindingName = ((IntegrationObjectSupport)inputChannel).getComponentName(); + if (StringUtils.hasText(inputBindingName)) { + this.functionProperties.setConsumerProperties(this.bindingServiceProperties.getConsumerProperties(inputBindingName)); + } + } + + if (outputChannel instanceof IntegrationObjectSupport) { + String outputBindingName = ((IntegrationObjectSupport)outputChannel).getComponentName(); + if (StringUtils.hasText(outputBindingName)) { + this.functionProperties.setProducerProperties(this.bindingServiceProperties.getProducerProperties(outputBindingName)); + } + } + IntegrationFlowBuilder flowBuilder = IntegrationFlows.from(inputChannel).bridge(); if (!this.andThenFunction(flowBuilder, outputChannel, this.functionProperties)) { diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/SourceToFunctionsSupportTests.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/SourceToFunctionsSupportTests.java index 5b47bf548..08ab6c9ee 100644 --- a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/SourceToFunctionsSupportTests.java +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/SourceToFunctionsSupportTests.java @@ -26,7 +26,6 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import reactor.core.publisher.Flux; -import org.springframework.beans.BeanInstantiationException; import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.WebApplicationType; @@ -49,10 +48,6 @@ import org.springframework.util.Assert; import org.springframework.util.MimeTypeUtils; import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.CoreMatchers.allOf; -import static org.hamcrest.CoreMatchers.endsWith; -import static org.hamcrest.CoreMatchers.isA; -import static org.hamcrest.Matchers.hasProperty; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -169,9 +164,6 @@ public class SourceToFunctionsSupportTests { public void testFunctionDoesNotExist() { expectedException.expect(BeanCreationException.class); - expectedException.expectCause( - allOf(isA(BeanInstantiationException.class), hasProperty("cause", isA(IllegalArgumentException.class)), - hasProperty("message", endsWith("'doesNotExist' cannot be located.")))); new SpringApplicationBuilder( TestChannelBinderConfiguration.getCompleteConfiguration(SupplierConfiguration.class)).web(