使用 Camel http4 将消息发送到数量不断变化的端点

Sending message to a changing number of endpoints using Camel http4

我创建了以下代码,我想使用 camel HTTP4 将相同的 JSON 正文发送到多个端点,而不仅仅是一个端点。端点的数量可能会随着时间而改变。

                    .choice()
                        .when(simple("${body} != null"))
                              .setHeader(Exchange.HTTP_METHOD, constant("POST"))
                              .setHeader(Exchange.HTTP_URI, simple(url))
                              .setProperty("ObjectBody", body())
                              .to("http4://someEndpoint?throwExceptionOnFailure=true&httpClient.socketTimeout=300000")
                        .otherwise()
                            .log(LoggingLevel.ERROR, "Incoming request has empty body")
                        .endChoice()
                    .end()

我正在尝试找出在这种情况下配置和使用多个端点的最佳方式。

我看过多播 EIP,但看起来我必须事先知道端点的数量。

非常感谢任何想法!

你看过 RouteBox 了吗?

THE NEED FOR A CAMEL ROUTEBOX ENDPOINT The routebox component is designed to ease integration in complex environments needing a large collection of routes and involving a wide set of endpoint technologies needing integration in different ways

In such environments, it is often necessary to craft an integration solution by creating a sense of layering among camel routes effectively organizing them into

Coarse grained or higher level routes - aggregated collection of inner or lower level routes exposed as Routebox endpoints that represent an integration focus area. For example

https://camel.apache.org/components/2.x/routebox-component.html

它的用法:

from ("direct:sendToMapBasedRoutebox")
    .setHeader("ROUTE_DISPATCH_KEY", constant("addToCatalog"))
    .to("routebox:multipleRoutes?innerRegistry=#registry&routeBuilders=#routes&dispatchMap=#map")
    .to("log:Routes operation performed?showAll=true");

那么理论上这应该将请求分散到由 RouteBox 封装的所有(路由)。

(在您的情况下是动态的)recipientList 正是您所需要的! 参见 https://camel.apache.org/components/3.14.x/eips/recipientList-eip.html