7 Replies Latest reply on Oct 27, 2009 8:42 PM by Willem Jiang

    Threading in Router??

    sriram_imshriram Novice

      Hi,

        Is it possible to implement threading in router?

      When using the wired tap (mulitcast) does camel follow any threading in the backround running the two end points separately?

        • 1. Re: Threading in Router??
          Claus Ibsen Master

          The multicast can work either in parallel or sequential mode AFAIR.

           

          In sequential it uses the same thread as the caller. In parallel it uses a new task for each step in the multicast. You use enable the parallel using parallelProcessing option on it.

           

          It uses the ExecutorService that has been configured it. There is a default configuration which uses a pool of 10 threads.

           

          In Camel 2.2 we have on the roadmap for easy thread pool configuration.

          There are tickets in JIRA about this.

           

          You can now in Camel 2.0 configure this manually using the setExecutorService methods.

           

           

          If you use the wireTap DSL then it uses a new task for the tapped exchange.

          • 2. Re: Threading in Router??
            sriram_imshriram Novice

            I havent used ExecutorService before. Can you please throw some light on it? Is there any sample available to guide us on it?

            Also is it available only for Camel 2.0+?

            • 3. Re: Threading in Router??
              Claus Ibsen Master

              No its also part of Camel 1.x

               

              You can read about it as its part of JDK itself. So do a bit of googling and check the javadoc.

              • 4. Re: Threading in Router??
                Willem Jiang Master

                Here is the dsl which is taken from loan_broker_example

                // Router 1 to call the bank endpoints sequentially

                        from(Constants.LOANBROKER_URI)

                            // Using the CreditScoreProcessor to call the credit agency service

                            .process(new CreditScoreProcessor(Constants.CREDITAGENCY_ADDRESS))

                                // Set the aggregation strategy on the multicast pattern

                                .multicast(new BankResponseAggregationStrategy())

                                    // Send out the request to three different banks sequentially

                                    .to(Constants.BANK1_URI, Constants.BANK2_URI, Constants.BANK3_URI);

                 

                        // Router 2 to call the bank endpoints in parallel

                        from(Constants.PARALLEL_LOANBROKER_URI)

                            .process(new CreditScoreProcessor(Constants.CREDITAGENCY_ADDRESS))

                                // Using the thread pool to send out messages to three different banks in parallel               

                                .multicast(new BankResponseAggregationStrategy())

                                    // Camel will create a thread pool with the default size (10)

                                    // for sending the message in parallel

                                    .parallelProcessing()

                                    .to(Constants.BANK1_URI, Constants.BANK2_URI, Constants.BANK3_URI);

                • 5. Re: Threading in Router??
                  David Valeri Newbie

                  It is part of Camel 1.x; however, the default executor is fairly restrictive.  This is the default executor that gets created in the MultiCastProcessor:

                   

                  this.executor = new ThreadPoolExecutor(processors.size(), processors.size(), 0, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(1000));

                           

                          from("seda:inputParallelEndpoint?concurrentConsumers=5")

                              .multicast()

                                  .parallelProcessing()

                                  .executor(pool)

                                  .to("mock:a", "mock:b", "bean:delayer")

                              .to("mock:c");

                  • 6. Re: Threading in Router??
                    Claus Ibsen Master

                    Ah well spotted.

                     

                    Do you mind creating a ticket in JIRA?

                    http://issues.apache.org/activemq/browse/CAMEL