Loading
 
What's Next: View All Tutorial →

Multicast Parallel Processing in Apache Camel

By Default Multicast invokes each endpoint sequentially. Parallel processing, allows us to execute all the endpoint at the same time, We can maintain timeout and the stopOnException during paralell processing Program   package com.myco...

Published Date: 05/05/2015  Last Modified Date: 05/05/2015    New Post



By Default Multicast invokes each endpoint sequentially.

Parallel processing, allows us to execute all the endpoint at the same time, We can maintain timeout and the stopOnException during paralell processing

Program
 
package com.mycompany.camel;

import org.apache.camel.CamelContext;
import org.apache.camel.ExchangePattern;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;

public class CamelMulticast {

    public static void main(String args[]) throws Exception {

        CamelContext context = new DefaultCamelContext();
        context.addRoutes(new RouteBuilder() {

            @Override
            public void configure() throws Exception {
                from("direct:A")
                        .multicast().parallelProcessing()
                        .to("direct:B", "direct:C", "direct:D")
                        .end();

                from("direct:B").setBody(simple("${body} - MessageB", String.class))
                        .log("${body}").end();
                from("direct:C").setBody(simple("${body} - MessageC", String.class))
                        .log("${body}").end();
                from("direct:D").setBody(simple("${body} - MessageD", String.class))
                        .log("${body}").end();
            }
        });
        context.start();
        ProducerTemplate producer = context.createProducerTemplate();

        Object res = producer.sendBody("direct:A", ExchangePattern.InOut, "MessageA");
        System.out.println(res);

    }
}


Output at first time execution:
route3                         INFO  MessageA - MessageC
route2                         INFO  MessageA - MessageB
route4                         INFO  MessageA - MessageD
MessageA - MessageD

Output at second time execution:
route3                         INFO  MessageA - MessageC
route4                         INFO  MessageA - MessageD
route2                         INFO  MessageA - MessageB
MessageA - MessageD

 
Awaiting for Administrator approval





Tags: Basic Multicast EIP

← Back to list


Related Post




×