Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between apache camel multicast and recipent-list patterns?

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):

  • http://camel.apache.org/recipient-list.html
  • http://camel.apache.org/recipientlist-annotation.html

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:

  • http://camel.apache.org/multicast.html
  • http://camel.apache.org/dynamic-router.html

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?
like image 957
Flame_Phoenix Avatar asked Nov 10 '13 12:11

Flame_Phoenix


1 Answers

  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.

like image 190
Petter Nordlander Avatar answered Oct 19 '22 06:10

Petter Nordlander