Return-Path: X-Original-To: apmail-camel-users-archive@www.apache.org Delivered-To: apmail-camel-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2372919CDE for ; Wed, 6 Apr 2016 16:13:48 +0000 (UTC) Received: (qmail 15934 invoked by uid 500); 6 Apr 2016 16:13:47 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 15871 invoked by uid 500); 6 Apr 2016 16:13:47 -0000 Mailing-List: contact users-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@camel.apache.org Delivered-To: mailing list users@camel.apache.org Received: (qmail 15845 invoked by uid 99); 6 Apr 2016 16:13:46 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Apr 2016 16:13:46 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 776871800EE for ; Wed, 6 Apr 2016 16:13:46 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.179 X-Spam-Level: * X-Spam-Status: No, score=1.179 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id hTxb4zXmRxaS for ; Wed, 6 Apr 2016 16:13:44 +0000 (UTC) Received: from mail-wm0-f41.google.com (mail-wm0-f41.google.com [74.125.82.41]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id C4D345F19B for ; Wed, 6 Apr 2016 16:13:38 +0000 (UTC) Received: by mail-wm0-f41.google.com with SMTP id u206so52662744wme.1 for ; Wed, 06 Apr 2016 09:13:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to; bh=cJ/OKlBMlvyP3s+04Rh/6SDt8OqO+pV3DqPxl3ftqZA=; b=biaun8Bn/NCL7Qmmq5NUEERFqaWb4ApYm5UkeizjBRiMg6u0sI3Vjqyj3jiGsjc8Rp xO2aX88E5+t7llsNSm3vJ8KyP8VHlNKtlU5nf+CA6ciAEs1adaNgVSeEUjDBNZBHSBAV z26z3aA0SLh4ghSzzujp4OnsQZAZqxkHEd0H9KuyEA0Yzq/xSYO36aKhH5iI47rbEoyT KeuFC7lx1fFP65dvbklKWblVXxR8RATCjlOyxQfV1AiiG+TJU7o9X5J4lI1dXr4btAlp yufr9Kpr0LL6g/wP9EJkFD19PlevV3FpIp7I+V2OzD+i4QSUUB1aalYthmyW9XOqKc9P Isbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to; bh=cJ/OKlBMlvyP3s+04Rh/6SDt8OqO+pV3DqPxl3ftqZA=; b=glu0/aChyycokqARRuWFTXtDsLx6uOT0VcYIVGbcSnKwD8KpwFzYlJ+u08cSL6hFZk 4sqz0xYuoR1J07lMXoYTLgACLobqMuKEu78n1lAd/FY2cwbXaeYiDoPbUjBoVkkU8MYb 9MthQdvXBUmfuCf2IR4N3gWcMPJ1Q19xHLO+wfSMFm8yvZLqzMjw55qGn4CiZzS6U0Ni d2uQnOOKgG49RFBbn0i5peR2O76RAjQBOijN6eo4vcIWdRPn3ka4ecl8iHcoC+GhhEvj pUNn11/vXRggPxIcYFyz/neaaoh6tPU58qrs+Uvjf5znPM6uqSR6vq80KhB+huSTgIMT OrrA== X-Gm-Message-State: AD7BkJJ/05kXANUGyYScJibBKExu15pWny++Ia9NN8qHs4a4kClJn3Xvz7BVf8XGqzAYDw== X-Received: by 10.28.98.137 with SMTP id w131mr24976241wmb.30.1459959217245; Wed, 06 Apr 2016 09:13:37 -0700 (PDT) Received: from unknown6003088a2396.domain_not_set.invalid ([88.202.149.90]) by smtp.googlemail.com with ESMTPSA id gk4sm3979413wjd.7.2016.04.06.09.13.36 for (version=TLSv1/SSLv3 cipher=OTHER); Wed, 06 Apr 2016 09:13:36 -0700 (PDT) Subject: Re: CDI questions To: users@camel.apache.org References: <57051ADE.1070607@gmail.com> From: Tim Dudgeon Message-ID: <570535AF.4010708@gmail.com> Date: Wed, 6 Apr 2016 17:13:35 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Thunderbird/38.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------000000030304090802080805" --------------000000030304090802080805 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Hi Antonin I tried your suggestion for problem 2, but couldn't get it to work. I've put an example that illustrates both problems here: https://github.com/tdudgeon/camel-cdi-servlet-example To reproduce the first problem just remove the @ContextName annotation from the HelloRoute class. To reproduce the second one uncomment line 25 from the same class. Tim On 06/04/2016 16:09, Antonin Stefanutti wrote: > Hi Tim, > >> On 06 Apr 2016, at 16:19, Tim Dudgeon wrote: >> >> I've found a couple of things I don't understand when using the camel-cdi component. >> >> 1. The @ContextName("customname") annotation can be used to specify a custom name for the camel context. But I'm finding that this annotation is essential. >> e.g. if my app comprise just of a couple of classes extending RoutBuilder then I MUST have this annotation present. >> I would have assumed that if I only have a single CamelContext then this would have been unnecessary? > This should work as you assume. For example, if you execute the following test: > > @RunWith(Arquillian.class) > public class CdiTest { > > @Deployment > public static Archive deployment() { > return ShrinkWrap.create(JavaArchive.class) > // Camel CDI > .addPackage(CdiCamelExtension.class.getPackage()) > // Bean archive deployment descriptor > .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); > } > > static class FirstRoute extends RouteBuilder { > > @Override > public void configure() { > from("direct:first").to("mock:first"); > } > } > > static class SecondRoute extends RouteBuilder { > > @Override > public void configure() { > from("direct:second").to("mock:second"); > } > } > > @Test > public void test() { > } > } > > You see that the two route builders get added to the default Camel context: > > 2016-04-06 16:56:53,201 INFO [ main] o.a.c.c.CdiCamelExtension : Camel CDI is starting Camel context [camel-1] > 2016-04-06 16:56:53,202 INFO [ main] o.a.c.i.DefaultCamelContext : Apache Camel 2.17.0 (CamelContext: camel-1) is starting > 2016-04-06 16:56:53,581 INFO [ main] o.a.c.i.DefaultCamelContext : Route: route1 started and consuming from: Endpoint[direct://second] > 2016-04-06 16:56:53,585 INFO [ main] o.a.c.i.DefaultCamelContext : Route: route2 started and consuming from: Endpoint[direct://first] > 2016-04-06 16:56:53,586 INFO [ main] o.a.c.i.DefaultCamelContext : Total 2 routes, of which 2 are started. > 2016-04-06 16:56:53,587 INFO [ main] o.a.c.i.DefaultCamelContext : Apache Camel 2.17.0 (CamelContext: camel-1) started in 0.385 seconds > 2016-04-06 16:56:53,649 INFO [ main] o.a.c.c.CamelContextProducer : Camel CDI is stopping Camel context [camel-1] > 2016-04-06 16:56:53,649 INFO [ main] o.a.c.i.DefaultCamelContext : Apache Camel 2.17.0 (CamelContext: camel-1) is shutting down > 2016-04-06 16:56:53,651 INFO [ main] o.a.c.i.DefaultShutdownStrategy : Starting to graceful shutdown 2 routes (timeout 300 seconds) > 2016-04-06 16:56:53,655 INFO [ - ShutdownTask] o.a.c.i.DefaultShutdownStrategy : Route: route2 shutdown complete, was consuming from: Endpoint[direct://first] > 2016-04-06 16:56:53,655 INFO [ - ShutdownTask] o.a.c.i.DefaultShutdownStrategy : Route: route1 shutdown complete, was consuming from: Endpoint[direct://second] > 2016-04-06 16:56:53,656 INFO [ main] o.a.c.i.DefaultShutdownStrategy : Graceful shutdown of 2 routes completed in 0 seconds > 2016-04-06 16:56:53,660 INFO [ main] o.a.c.i.DefaultCamelContext : Apache Camel 2.17.0 (CamelContext: camel-1) uptime 0.459 seconds > 2016-04-06 16:56:53,660 INFO [ main] o.a.c.i.DefaultCamelContext : Apache Camel 2.17.0 (CamelContext: camel-1) is shutdown in 0.011 seconds > > Could you please send more details about your deployment so that I can help identify why that is not working as expected? > >> 2. I'm try to use a custom thread pool. As described in the docs I use a @Producer to generate the thread pool profile: >> >> public class CamelContextFactory { >> >> @Produces >> @ApplicationScoped >> CamelContext customize() { >> DefaultCamelContext context = new DefaultCamelContext(); >> context.setName("mycontext"); >> ThreadPoolProfile profile = new ThreadPoolProfileBuilder("poolName").poolSize(4).maxPoolSize(50).build(); >> context.getExecutorServiceManager().registerThreadPoolProfile(profile); >> return context; >> } >> } >> >> This seems to be executed as expected, but when I try to use the thread pool in a route like this: >> >> from("direct:foo" ) >> .threads().executorServiceRef("poolName") >> .log("route executed"); >> >> then the pool can't be found: >> >> Caused by: java.lang.IllegalArgumentException: ExecutorServiceRef poolName not found in registry or as a thread pool profile. > The lookup is done by name so you need to have a @Named("poolName") bean deployed or have the ExecutorService register manually into the Camel context (which you do but for some reasons it does not get found). > > So in your example, I would try: > > @Produces > @Named("poolName") > ThreadPoolProfile profile() { > return ThreadPoolProfileBuilder("poolName").poolSize(4).maxPoolSize(50).build(); > } > > And without using a custom Camel context. > >> Thanks for any advice on these. >> Tim > Let me know if that helps. > > Antonin > --------------000000030304090802080805--