Search code examples
javaapache-camelspring-integrationenterprise-integration

Do any java Enterprise Integration Pattern (EIP) frameworks support chaining together EIPs?


There are at least two popular java EIP frameworks: Spring Integration and Apache Camel. They both have fluent programming interfaces that make it easy to implement complex EIPs. Here's an example of Apache Camel using the Aggregator EIP.

I'm interested in chaining together multiple EIPs. For example: Read from queue1, do some transformation, write to queue 2, read from queue 2, aggregate messages, write to queue3.

Apache Camel enables this, but it requires defining multiple Routes. Something like this:

from("seda:queue1")
.process(new SomeProcessor())
.to("seda:queue2");

from("seda:queue2")
.aggregate(new AggregationStrategy())
.to("seda:queue3");

I'm interested in a way to chain the two routes together, something like this:

from("seda:queue1")
.process(new SomeProcessor())
.to("seda:queue2")
.andThen()
.aggregate(new AggregationStrategy())
.to("seda:queue3");

Is there a way to do this in Apache Camel or Spring Integration?


Solution

  • With Spring Integration it is possible via its Java DSL:

    @Bean
    IntegrationFlow myFlow() {
        return IntegrationFlow.from("queue1")
                    .handle(new SomeProcessor())
                    .channel("queue2")
                    .aggregate()
                    .channel("queue3")
                    .get();
    }
    

    See more info in the documentation: https://docs.spring.io/spring-integration/docs/current/reference/html/dsl.html#java-dsl

    You really can chose whatever implementation of the MessageChannel you need to use in between those EIPs: https://docs.spring.io/spring-integration/docs/current/reference/html/core.html#channel-implementations