0

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?

sparty02
  • 566
  • 1
  • 6
  • 13

2 Answers2

0

composedFlow.start();

That's not enough; you need to register dynamic flows with the IntegrationFlowContext so all the supporting beans are registered with the application context.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
0

Autowire IntegrationFlowContext ...

@Autowired
IntegrationFlowContext integrationFlowContext;

Then register your flow... ...

   integrationFlowContext.registration(integrationFlow).register();
Kevvvvyp
  • 1,704
  • 2
  • 18
  • 38