Tim, For the second problem, I’ve just looked at how Camel looks up for the custom ExecutorService and it actually looks up the CDI registry for a named bean of type ExecutorService, so you can just produce your custom ExecutorService instead of a ThreadPoolProfile bean. Otherwise, it falls back to the configured ExecutorServiceManager so your first way of doing it (with a custom Camel context) should work with Camel 2.17.0.
Antonin > On 06 Apr 2016, at 19:00, Antonin Stefanutti <anto...@stefanutti.fr> wrote: > > Hi Tim, > > I see that it uses Camel 2.16.2. The Camel CDI component has been rewritten > and improved in Camel 2.17.0. > > Could you upgrade your Camel dependencies to 2.17.0 version? That should > solve the issues. > > Antonin > >> On 06 Apr 2016, at 18:13, Tim Dudgeon <tdudgeon...@gmail.com> wrote: >> >> 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 <tdudgeon...@gmail.com> 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 >>> >> >