@@ -0,0 +1,3954 @@
+/**%0A * Licensed to the Apache Software Foundation (ASF) under one or more%0A * contributor license agreements.  See the NOTICE file distributed with%0A * this work for additional information regarding copyright ownership.%0A * The ASF licenses this file to You under the Apache License, Version 2.0%0A * (the %22License%22); you may not use this file except in compliance with%0A * the License.  You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage camelinaction;%0A%0Aimport java.util.concurrent.ExecutorService;%0Aimport java.util.concurrent.Executors;%0A%0Aimport javax.jms.ConnectionFactory;%0A%0Aimport org.apache.activemq.ActiveMQConnectionFactory;%0Aimport org.apache.camel.CamelContext;%0Aimport org.apache.camel.Exchange;%0Aimport org.apache.camel.Processor;%0Aimport org.apache.camel.builder.RouteBuilder;%0Aimport org.apache.camel.component.jms.JmsComponent;%0Aimport org.apache.camel.impl.DefaultCamelContext;%0A%0A/**%0A * A route that polls an FTP server for new orders, downloads them, converts the order %0A * file into a JMS Message and then sends it to the JMS incomingOrders queue hosted %0A * on an embedded ActiveMQ broker instance.%0A *%0A * @author janstey%0A *%0A */%0Apublic class OrderRouterWithParallelMulticast %7B%0A%0A    public static void main(String args%5B%5D) throws Exception %7B%0A        // create CamelContext%0A        CamelContext context = new DefaultCamelContext();%0A        %0A        // connect to embedded ActiveMQ JMS broker%0A        ConnectionFactory connectionFactory = %0A            new ActiveMQConnectionFactory(%22vm://localhost%22);%0A        context.addComponent(%22jms%22,%0A            JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));%0A%0A        // add our route to the CamelContext%0A        context.addRoutes(new RouteBuilder() %7B%0A            public void configure() %7B%0A                // load file orders from src/data into the JMS queue%0A                from(%22file:src/data?noop=true%22).to(%22jms:incomingOrders%22);%0A        %0A                // content-based router%0A                from(%22jms:incomingOrders%22)%0A                .choice()%0A                    .when(header(%22CamelFileName%22).endsWith(%22.xml%22))%0A                        .to(%22jms:xmlOrders%22)  %0A                    .when(header(%22CamelFileName%22).regex(%22%5E.*(csv%7Ccsl)$%22))%0A                        .to(%22jms:csvOrders%22)%0A                    .otherwise()%0A                        .to(%22jms:badOrders%22);        %0A                %0A                ExecutorService executor = Executors.newFixedThreadPool(16);%0A                %0A                from(%22jms:xmlOrders%22)%0A                    .multicast().parallelProcessing().executorService(executor)%0A                    .to(%22jms:accounting%22, %22jms:production%22);%0A                %0A                // test that our route is working%0A                from(%22jms:accounting%22).process(new Processor() %7B%0A                    public void process(Exchange exchange) throws Exception %7B%0A                        System.out.println(%22Accounting received order: %22 %0A                                + exchange.getIn().getHeader(%22CamelFileName%22));   %0A                    %7D%0A                %7D);                %0A                from(%22jms:production%22).process(new Processor() %7B%0A                    public void process(Exchange exchange) throws Exception %7B%0A                        System.out.println(%22Production received order: %22 %0A                                + exchange.getIn().getHeader(%22CamelFileName%22));   %0A                    %7D%0A                %7D);%0A            %7D%0A        %7D);%0A%0A        // start the route and let it do its work%0A        context.start();%0A        Thread.sleep(2000);%0A%0A        // stop the CamelContext%0A        context.stop();%0A    %7D%0A%7D%0A

add parallel multicast