From 63e715a685ac8f53d80629a6728b168b1faab7c0 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Mon, 30 Jan 2017 13:19:01 -0500 Subject: [PATCH] DSL-140: Improve Logic for outputChannel in DSL Fixes spring-projects/spring-integration-java-dsl#140 Allow to provide any custom `MessageProducer` impl for the `.handle()`, not only `AbstractReplyProducingMessageHandler` extension Polishing --- .../dsl/IntegrationFlowDefinition.java | 27 +++++++---- .../dsl/manualflow/ManualFlowTests.java | 46 ++++++++++++++++++- 2 files changed, 64 insertions(+), 9 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dsl/IntegrationFlowDefinition.java b/spring-integration-core/src/main/java/org/springframework/integration/dsl/IntegrationFlowDefinition.java index c8a2e5239a..a11cb21c18 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dsl/IntegrationFlowDefinition.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dsl/IntegrationFlowDefinition.java @@ -45,6 +45,7 @@ import org.springframework.integration.config.ConsumerEndpointFactoryBean; import org.springframework.integration.config.SourcePollingChannelAdapterFactoryBean; import org.springframework.integration.context.IntegrationContextUtils; import org.springframework.integration.core.GenericSelector; +import org.springframework.integration.core.MessageProducer; import org.springframework.integration.core.MessageSelector; import org.springframework.integration.dsl.channel.MessageChannelSpec; import org.springframework.integration.dsl.channel.WireTapSpec; @@ -117,7 +118,7 @@ public abstract class IntegrationFlowDefinition REFERENCED_REPLY_PRODUCERS = new HashSet<>(); + private static final Set REFERENCED_REPLY_PRODUCERS = new HashSet<>(); protected final Set integrationComponents = new LinkedHashSet<>(); @@ -2821,12 +2822,22 @@ public abstract class IntegrationFlowDefinition message) throws MessagingException { + this.outputChannel.send(message); + } + + } + + + PollableChannel resultChannel = new QueueChannel(); + + IntegrationFlowRegistration flowRegistration = + this.integrationFlowContext.registration(flow -> + flow.handle(new MessageProducingHandler()) + .channel(resultChannel)) + .register(); + + this.integrationFlowContext.messagingTemplateFor(flowRegistration.getId()) + .send(new GenericMessage<>("test")); + + Message receive = resultChannel.receive(1000); + assertNotNull(receive); + assertEquals("test", receive.getPayload()); + } + @Configuration @EnableIntegration public static class RootConfiguration {