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 <[email protected]> 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 <[email protected]>
> > > 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.
> > > >
> > >
> > >
>
>