Question

So, after reading some documentation and getting a lot of help from you guys here, I finally implemented a recipient list that chooses the endpoints dynamically (a dynamic recipient list):

In my code, MainApp_A generates reports every 10 seconds, and I want it to send the reports to all the servers at the same time, instead of doing it one by one. Thus I have developed the following route.

MainApp_A

main.addRouteBuilder(new RouteBuilder(){
    @Override
        public void configure() throws Exception {
            from("direct:start").multicast().parallelProcessing()
                .beanRef("recipientListBean", "route").end()
            .log("${body}");
        }
});

RecipientListBean

@RecipientList
public Set<String> route(String body) {
        return servers; //returns a collection of several severs
}

I also checked the documentation for the Multicast pattern and the Dynamic route:

Now I have a few questions and I am confused. So I have a few questions:

  1. Is the recipient dynamic list simply the junction of the Multicast pattern with the Dynamic Route Pattern?
  2. the multicast() call alone is purely sequential right? What is the difference between using multicast() and recipientList()?
  3. For both multicast() and recipientList() to be concorrent I have to use parallelProcessing(). In my case, which is more efficient?
Was it helpful?

Solution

  1. The dynamic router is used to evaluate which endpoints to send a specific message to at runtime, one endpoint at a time. Recipient List is a set of endpoints to send the very same message to.

I recommend you to read EAI patterns by Gregor Hohpe and Bobby Woolf for some background and insight.

http://www.eaipatterns.com/

  1. Multicast allows a hard coded recipient list and recipientList(..) allows endpoints computed at runtime. Both are "recipient lists".

  2. They will likely be equally efficient, if you don't have a lot of logic (say DB lookups) computing the endpoints in the recipient list - the invocation of the endpoints is likely by far the hardest part for Camel. Anyway - a static "multicast" is more readable.

In Camel, a reason for choosing one construct over another is often readability of the route. You should be able to look at a route and follow what it does (given you know EIP). At least, that's a good aim.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top