lbma
lbma

Reputation: 132

Sending message to a changing number of endpoints using Camel http4

I have created the following piece of code and, instead of just one endpoint, I want to send the same JSON body to multiple endpoints using camel HTTP4. The number of endpoints is likely to change over time.

                    .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()

I'm trying to figure out the best way to configure and use multiple endpoints in this scenario.

I have looked at the Multicast EIP, but it looks like I would have to know the number of endpoints beforehand.

Any ideas are greatly appreciated!

Upvotes: 0

Views: 88

Answers (2)

TacheDeChoco
TacheDeChoco

Reputation: 3913

The (dynamic in your case) recipientList is what you need ! See https://camel.apache.org/components/3.14.x/eips/recipientList-eip.html

Upvotes: 1

jcompetence
jcompetence

Reputation: 8383

Did you take a look at 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

Its usage:

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");

Then in theory this should fan out the requests towards all (routes) encapsulated by a RouteBox.

Upvotes: 0

Related Questions