Bootstraping Apache Camel - Main Method
Hi, I've boostraped apache camel like below. public static void main(String... args) throws Exception { Main main = new Main(); main.run(args); ProducerTemplate template = main.getCamelTemplate(); template.sendBody("direct://k", 2); } I have another bean with a method annotated with @Consumes which is never invoked. public class MyBean { @Consume(context = "camel-1",uri="direct://k") public void k(@Body Integer k) { System.out.println("This is k " + k); } } How do I get pojo consumer to work? Thanks, Chege.
Re: Bootstraping Apache Camel - Main Method
I tried below code but it didn't work. public class MyConfig { @BindToRegistry("myBean") public MyBean myBean() { return new MyBean(); } } On Mon, 2019-07-08 at 09:50 +0200, Claus Ibsen wrote: > How do you create that bean? > > You need to create it via Camel to have Camel detect those > annotations > > There is an Injector on CamelContext you can use to create a new > instance of the bean > > On Mon, Jul 8, 2019 at 9:35 AM chege wrote: > > > > Hi, > > > > I've boostraped apache camel like below. > > > > public static void main(String... args) throws Exception { > > Main main = new Main(); > > main.run(args); > > ProducerTemplate template = main.getCamelTemplate(); > > template.sendBody("direct://k", 2); > > } > > > > I have another bean with a method annotated with @Consumes which is > > never invoked. > > > > public class MyBean { > > > > @Consume(context = "camel-1",uri="direct://k") > > public void k(@Body Integer k) { > > System.out.println("This is k " + k); > > } > > > > } > > > > How do I get pojo consumer to work? > > > > Thanks, > > Chege. > > > >
Re: Bootstraping Apache Camel - Main Method
Using the injector works fine, what modification is needed to make below code work with the registry only. ... public static void main(String[] args) throws NamingException, Exception { DefaultRegistry registry = new DefaultRegistry(); registry.bind("myBean", new MyBean()); CamelContext cc = new DefaultCamelContext(registry); cc.start(); ProducerTemplate pt = cc.createProducerTemplate(); pt.sendBody("direct://k", 19876652); cc.stop(); } ... public class MyBean { @Consume(uri="direct://k") public void k(@Body Integer k) { System.out.println("This is k " + k); } } On Mon, 2019-07-08 at 10:31 +0200, Claus Ibsen wrote: > On Mon, Jul 8, 2019 at 10:06 AM chege wrote: > > > > I tried below code but it didn't work. > > > > public class MyConfig { > > > > @BindToRegistry("myBean") > > public MyBean myBean() { > > return new MyBean(); > > } > > > > } > > > > Try with > > @... > public MyBean myBean(CamelContext context) { > return context.getInjector().newInstance(MyBean.class); > } > > a) > We could also consider letting Camel Main bean post process these > automatic, so you can just do as you did, and Camel does its other > magic to detect those @Conume annotations and whatnot > > b) > We could consider having this on fields so you can do > > @BindToRegistry > private MyBean myBean; > > And if it has a default no-arg ctr we create and inject it automatic > (I frankly can't remember if we dont already have that) if you add > this to config classes or route builders via main > > > > On Mon, 2019-07-08 at 09:50 +0200, Claus Ibsen wrote: > > > How do you create that bean? > > > > > > You need to create it via Camel to have Camel detect those > > > annotations > > > > > > There is an Injector on CamelContext you can use to create a new > > > instance of the bean > > > > > > On Mon, Jul 8, 2019 at 9:35 AM chege > > > wrote: > > > > > > > > Hi, > > > > > > > > I've boostraped apache camel like below. > > > > > > > > public static void main(String... args) throws Exception { > > > > Main main = new Main(); > > > > main.run(args); > > > > ProducerTemplate template = main.getCamelTemplate(); > > > > template.sendBody("direct://k", 2); > > > > } > > > > > > > > I have another bean with a method annotated with @Consumes > > > > which is > > > > never invoked. > > > > > > > > public class MyBean { > > > > > > > > @Consume(context = "camel-1",uri="direct://k") > > > > public void k(@Body Integer k) { > > > > System.out.println("This is k " + k); > > > > } > > > > > > > > } > > > > > > > > How do I get pojo consumer to work? > > > > > > > > Thanks, > > > > Chege. > > > > > > > > > > > >
Re: Bootstraping Apache Camel - Main Method
Works fine :-) On Mon, 2019-07-08 at 11:19 +0200, Claus Ibsen wrote: > Just add to the registry after you have created camel context, and > use > its injector to create the bean, before you start camel > > On Mon, Jul 8, 2019 at 11:15 AM chege wrote: > > > > Using the injector works fine, what modification is needed to make > > below code work with the registry only. > > > > ... > > public static void main(String[] args) throws NamingException, > > Exception { > > > > > > DefaultRegistry registry = new DefaultRegistry(); > > registry.bind("myBean", new MyBean()); > > > > CamelContext cc = new DefaultCamelContext(registry); > > cc.start(); > > ProducerTemplate pt = cc.createProducerTemplate(); > > pt.sendBody("direct://k", 19876652); > > cc.stop(); > > } > > ... > > > > > > public class MyBean { > > > > @Consume(uri="direct://k") > > public void k(@Body Integer k) { > > System.out.println("This is k " + k); > > } > > > > } > > > > On Mon, 2019-07-08 at 10:31 +0200, Claus Ibsen wrote: > > > On Mon, Jul 8, 2019 at 10:06 AM chege > > > wrote: > > > > > > > > I tried below code but it didn't work. > > > > > > > > public class MyConfig { > > > > > > > > @BindToRegistry("myBean") > > > > public MyBean myBean() { > > > > return new MyBean(); > > > > } > > > > > > > > } > > > > > > > > > > Try with > > > > > > @... > > > public MyBean myBean(CamelContext context) { > > > return context.getInjector().newInstance(MyBean.class); > > > } > > > > > > a) > > > We could also consider letting Camel Main bean post process these > > > automatic, so you can just do as you did, and Camel does its > > > other > > > magic to detect those @Conume annotations and whatnot > > > > > > b) > > > We could consider having this on fields so you can do > > > > > > @BindToRegistry > > > private MyBean myBean; > > > > > > And if it has a default no-arg ctr we create and inject it > > > automatic > > > (I frankly can't remember if we dont already have that) if you > > > add > > > this to config classes or route builders via main > > > > > > > > > > On Mon, 2019-07-08 at 09:50 +0200, Claus Ibsen wrote: > > > > > How do you create that bean? > > > > > > > > > > You need to create it via Camel to have Camel detect those > > > > > annotations > > > > > > > > > > There is an Injector on CamelContext you can use to create a > > > > > new > > > > > instance of the bean > > > > > > > > > > On Mon, Jul 8, 2019 at 9:35 AM chege > > > > > wrote: > > > > > > > > > > > > Hi, > > > > > > > > > > > > I've boostraped apache camel like below. > > > > > > > > > > > > public static void main(String... args) throws Exception { > > > > > > Main main = new Main(); > > > > > > main.run(args); > > > > > > ProducerTemplate template = > > > > > > main.getCamelTemplate(); > > > > > > template.sendBody("direct://k", 2); > > > > > > } > > > > > > > > > > > > I have another bean with a method annotated with @Consumes > > > > > > which is > > > > > > never invoked. > > > > > > > > > > > > public class MyBean { > > > > > > > > > > > > @Consume(context = "camel-1",uri="direct://k") > > > > > > public void k(@Body Integer k) { > > > > > > System.out.println("This is k " + k); > > > > > > } > > > > > > > > > > > > } > > > > > > > > > > > > How do I get pojo consumer to work? > > > > > > > > > > > > Thanks, > > > > > > Chege. > > > > > > > > > > > > > > > > > > > > > > > >
How to hande exceptions raised in "interceptSendToEndpoint"
Hi, I have a parent route builder that defines an interceptor and excpetion handler as follows. onException(Exception.class) .process(new Processor() { @Override public void process(Exchange exchange) throws Exception { System.out.println("Handling Error"); } }); interceptSendToEndpoint("velocity://*") .setHeader("includeplaintext", () -> "true") .setHeader("CamelVelocitySupplementalContext", method("mailRouter", "x")); Here is a simplified definition of method "x" public Map x(@Header("test") String schema) { throw new RuntimeException("error"); } Then I have a route that will trigger above interceptor defined as follows. from("activemq://queue:inquiryresponse") .routeId("Inquiry Response") .log("Sending Inquiry Response ${body}") .setHeader("subject", constant("Inquiry Response")) .setHeader("to", simple("${body['fname']}<${body['ccemail']}>")) .to("velocity://templates/inquiry_response.html") .to("bean:mailRouter?method=routeEmail") .log("Sent Inquiry Response ${body}"); The exception handler above is not invoked. What I am missing? Thanks, Chege.
How to display log messages when using camel-cdi insde payara micro
Hi, I have created an camel-cdi application inside payara micro which starts okey but the logs aren't showing up. What should I add for the logs to display properly. I have tried adding "commn-logging.properties" file with below content but still no results. org.apache.commons.logging.Log=org.apache.commons.logging.impl.Jdk14Logger #org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger Thanks.