I'm trying to figure out how to split up spring integration flows into multiple sub flows and compose them together. Ultimately, I'm trying to lay out a pattern in which I can create modules of subflows that can be pieced together for common integration recipes.
This test case represents a minimal example of trying (but failing) to wire together subflows using the DSL IntegrationFlow API:
@RunWith(SpringRunner.class)
@SpringBootTest(classes = { ComposedIntegrationFlowTest.class })
@SpringIntegrationTest
@EnableIntegration
public class ComposedIntegrationFlowTest {
@Test
public void test() {
MessageChannel beginningChannel = MessageChannels.direct("beginning").get();
IntegrationFlow middleFlow = f -> f
.transform("From middleFlow: "::concat)
.transform(String.class, String::toUpperCase);
IntegrationFlow endFlow = f -> f
.handle((p, h) -> "From endFlow: " + p);
StandardIntegrationFlow composedFlow = IntegrationFlows
.from(beginningChannel)
.gateway(middleFlow)
.gateway(endFlow)
.get();
composedFlow.start();
beginningChannel.send(MessageBuilder.withPayload("hello!").build());
}
}
Trying the above, I get:
org.springframework.messaging.MessageDeliveryException: Dispatcher has no subscribers for channel 'beginning'.; nested exception is org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers, failedMessage=GenericMessage [payload=hello!, headers={id=2b1de253-a822-42ba-cd85-009b83a644eb, timestamp=1537890950879}], failedMessage=GenericMessage [payload=hello!, headers={id=2b1de253-a822-42ba-cd85-009b83a644eb, timestamp=1537890950879}]
How do I piece together these subflows? Is there a better API for attempting to do this kind of composition? Is this integration test structured correctly?