Camel 是否有Java企业集成模式(EIP)框架支持将EIP链接在一起?

n8ghc7c1  于 2022-11-23  发布在  Apache
关注(0)|答案(1)|浏览(144)

至少有两种流行的java EIP框架:Spring Integration和Apache Camel。它们都有流畅的编程接口,可以轻松实现复杂的EIP。下面是Apache Camel使用聚合器EIP的一个示例。
我对链接多个EIP感兴趣。例如:从queue1读取,执行一些转换,写入队列2,从队列2读取,聚合消息,写入队列3。
Apache Camel支持此功能,但需要定义多个路由。

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

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

我感兴趣的是一种将两条路线链接在一起的方法,类似于以下内容:

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

在Apache Camel或Spring Integration中是否有办法做到这一点?

w51jfk4q

w51jfk4q1#

借助Spring Integration,可以通过其Java DSL实现以下功能:

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

有关更多信息,请参阅文档:https://docs.spring.io/spring-integration/docs/current/reference/html/dsl.html#java-dsl
您确实可以在这些EIP之间选择需要使用的MessageChannel的任何实现:https://docs.spring.io/spring-integration/docs/current/reference/html/core.html#channel-implementations

相关问题