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 52F8B19A51 for ; Wed, 6 Apr 2016 15:09:52 +0000 (UTC) Received: (qmail 51805 invoked by uid 500); 6 Apr 2016 15:09:51 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 51750 invoked by uid 500); 6 Apr 2016 15:09:51 -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 51734 invoked by uid 99); 6 Apr 2016 15:09:51 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Apr 2016 15:09:51 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 209B6C91BA for ; Wed, 6 Apr 2016 15:09:51 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.28 X-Spam-Level: X-Spam-Status: No, score=0.28 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id 4PwNRHYqEozp for ; Wed, 6 Apr 2016 15:09:49 +0000 (UTC) Received: from mo176.mail-out.ovh.net (mo176.mail-out.ovh.net [178.32.228.176]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id 2929E60F49 for ; Wed, 6 Apr 2016 15:09:48 +0000 (UTC) Received: from ex.mail.ovh.net (gw2.ex.mail.ovh.net [176.31.149.1]) by mo176.mail-out.ovh.net (Postfix) with SMTP id 66F59FF9227 for ; Wed, 6 Apr 2016 17:09:42 +0200 (CEST) From: Antonin Stefanutti To: "users@camel.apache.org" Subject: Re: CDI questions Thread-Topic: CDI questions Thread-Index: AQHRkA9NkKFu7QbjR0KSmiehnRTfhp986wkA Date: Wed, 6 Apr 2016 15:09:41 +0000 Message-ID: References: <57051ADE.1070607@gmail.com> In-Reply-To: <57051ADE.1070607@gmail.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: Apple Mail (2.3124) x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [88.182.187.4] Content-Type: text/plain; charset="us-ascii" Content-ID: <7DB37105CB3F504FB4FC5734DF99F387@indiv.local> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Ovh-Tracer-Id: 2789417020484920538 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeekkedrgedugdejlecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjnecuuegrihhlohhuthemuceftddtnecu Hi Tim, > On 06 Apr 2016, at 16:19, Tim Dudgeon wrote: >=20 > I've found a couple of things I don't understand when using the camel-cdi= component. >=20 > 1. The @ContextName("customname") annotation can be used to specify a cus= tom name for the camel context. But I'm finding that this annotation is ess= ential. > 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 t= est: @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.38= 5 seconds 2016-04-06 16:56:53,649 INFO [ main] o.a.c.c.CamelContextProduce= r : 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 dow= n 2016-04-06 16:56:53,651 INFO [ main] o.a.c.i.DefaultShutdownStra= tegy : Starting to graceful shutdown 2 routes (timeout 300 seconds= ) 2016-04-06 16:56:53,655 INFO [ - ShutdownTask] o.a.c.i.DefaultShutdownStra= tegy : Route: route2 shutdown complete, was consuming from: Endpoi= nt[direct://first] 2016-04-06 16:56:53,655 INFO [ - ShutdownTask] o.a.c.i.DefaultShutdownStra= tegy : Route: route1 shutdown complete, was consuming from: Endpoi= nt[direct://second] 2016-04-06 16:56:53,656 INFO [ main] o.a.c.i.DefaultShutdownStra= tegy : 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 se= conds 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: >=20 > public class CamelContextFactory { >=20 > @Produces > @ApplicationScoped > CamelContext customize() { > DefaultCamelContext context =3D new DefaultCamelContext(); > context.setName("mycontext"); > ThreadPoolProfile profile =3D new ThreadPoolProfileBuilder("poolName").po= olSize(4).maxPoolSize(50).build(); > context.getExecutorServiceManager().registerThreadPoolProfile(profile); > return context; > } > } >=20 > This seems to be executed as expected, but when I try to use the thread p= ool in a route like this: >=20 > from("direct:foo" ) > .threads().executorServiceRef("poolName") > .log("route executed"); >=20 > then the pool can't be found: >=20 > Caused by: java.lang.IllegalArgumentException: ExecutorServiceRef poolNam= e 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 de= ployed 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