Re: route <-> XML <-> route

2015-05-26 Thread Pontus Ullgren
On Tue, 26 May 2015 at 18:10 Tim Dudgeon  wrote:

> On 26/05/2015 16:55, Pontus Ullgren wrote:
> > Depending on the registry you use you can create the beans in java and
> add
> > them to the registry in runtime before you add (and start) the route in
> the
> > context.
> Yes, that's what I figured. Its the exact mechanism for doing so that
> I'm trying to figure out.
>

Since the Camel Registry interface does not have any put/add/register
method you will need to know what registry you are using and use methods
specific to that implementation. So if you use
org.apache.camel.impl.SimpleRegistry you can do something like this.

SimpleRegistry myRegistry = (SimpleRegistry)camelContext.getRegistry();
myRegistry.put("myBeanName", new MyBean());

if you use a Spring and a SpringRouteBuilder to configure your routes you
can do something like this.
ConfigurableListableBeanFactory beanFactory =
((ConfigurableApplicationContext)getApplicationContext()).getBeanFactory();
MyBean bean = new MyBean();
beanFactory.autowireBean(bean);
beanFactory.initializeBean(bean, "myBeanName");
beanFactory.registerSingleton("myBeanName", bean);

There are probably similar ways of doing things with guice, CDI, JNDI,
YourOwnMagicRegistry


> > I have some example code on how to do this using a spring registry.
> However
> > since you say you are not using spring you will have to figure out how to
> > add the beans programmatically to the registry implementation you are
> > using.
> I'm not currently using spring, but I could do so if there was a good
> reason too.
> Performance is a key issue. I'm finding that creating a new Spring
> ApplicationContext including Camel from XML is fairly slow (about 1.3s),
> whilst creating a new Camel context directly in Java (no Spring) is
> quite a bit faster (about 0.3s) whilst adding a new route to a running
> context is superfast (about 0.01s), hence the preferred option.
>
> Tim
>
> >
> > Best regards
> > Pontus
> >
> > On Tue, 26 May 2015 16:28 Tim Dudgeon  wrote:
> >
> >> The beans are defined at runtime, so can't go in the spring xml that is
> >> used on startup (and I'm not actually using spring, though could do if
> >> essential).
> >> I need to provide the route definition plus any beans it uses at
> >> runtime, after the context has started.
> >>
> >> Tim
> >>
> >> On 26/05/2015 15:23, Claus Ibsen wrote:
> >>> Hi
> >>>
> >>> If you are using spring xml then the beans need to go in the spring
> >>> xml file as .
> >>>
> >>> You may be able to add those beans later using some spring java api.
> >>>
> >>> On Tue, May 26, 2015 at 2:21 PM, Tim Dudgeon 
> >> wrote:
>  Sorry, not clear on this. Where does the  element go?
>  The XML generated from the route looks like this:
> 
>  
>  http://camel.apache.org/schema/spring";>
>  
>    
>    
>    
>  
>  
> 
> 
>  The  element would normally be part of the spring XML, but
> >> outside the
>  routes definition looking something like this:
> 
>  
>  
>  
> 
>  http://camel.apache.org/schema/spring";>
>    
>  
>    
>  
>  
> 
>  Can the beans be defined in this way at runtime or is some other
> >> mechanism
>  needed to instantiate the beans and add them to the registry
> >> independently
>  of adding the route (as XML)?
> 
>  Tim
> 
> 
> 
> 
>  On 26/05/2015 08:19, Claus Ibsen wrote:
> > Hi
> >
> > Yeah 
> >
> > On Tue, May 26, 2015 at 9:02 AM, Tim Dudgeon 
> > wrote:
> >> Yes, but how to specify the bean that is referenced? Can that be
> >> specified
> >> in the XML using a bean element as if it was being using on startup,
> >> or
> >> does
> >> it need to be added to the registry "manually"?
> >>
> >> Tim
> >>
> >>
> >> On 26/05/2015 07:49, Claus Ibsen wrote:
> >>> On Mon, May 25, 2015 at 3:01 PM, Tim Dudgeon <
> tdudgeon...@gmail.com>
> >>> wrote:
>  Hi,
> 
>  I'm wanting some guidance on how to generate a route definition
> >> using
>  the
>  API in a way that allows it to be converted to XML and then
> >> executed.
>  I've
>  got the basics sorted, but struggling on how to handle processors
> >> and
>  beans.
>  For instance, if I generate a route like this:
> 
>  // generate the route
>  RoutesDefinition routes1 = new RoutesDefinition()
>  RouteDefinition route = routes1.route()
>  route.from("timer://foo?fixedRate=true&period=200")
>  route.log("Hello World!")
>  route.process(new SimpleProcessor())
> 
>  // set route to context
>  CamelContext camelContext = new DefaultCamelContext()
>  camelContext.start()
>  camelContext.addRouteDefinitions(routes1.getRoutes())
> 
>  Then the route works fine (e.

Re: route <-> XML <-> route

2015-05-26 Thread Tim Dudgeon

On 26/05/2015 16:55, Pontus Ullgren wrote:

Depending on the registry you use you can create the beans in java and add
them to the registry in runtime before you add (and start) the route in the
context.
Yes, that's what I figured. Its the exact mechanism for doing so that 
I'm trying to figure out.


I have some example code on how to do this using a spring registry. However
since you say you are not using spring you will have to figure out how to
add the beans programmatically to the registry implementation you are
using.
I'm not currently using spring, but I could do so if there was a good 
reason too.
Performance is a key issue. I'm finding that creating a new Spring 
ApplicationContext including Camel from XML is fairly slow (about 1.3s), 
whilst creating a new Camel context directly in Java (no Spring) is 
quite a bit faster (about 0.3s) whilst adding a new route to a running 
context is superfast (about 0.01s), hence the preferred option.


Tim



Best regards
Pontus

On Tue, 26 May 2015 16:28 Tim Dudgeon  wrote:


The beans are defined at runtime, so can't go in the spring xml that is
used on startup (and I'm not actually using spring, though could do if
essential).
I need to provide the route definition plus any beans it uses at
runtime, after the context has started.

Tim

On 26/05/2015 15:23, Claus Ibsen wrote:

Hi

If you are using spring xml then the beans need to go in the spring
xml file as .

You may be able to add those beans later using some spring java api.

On Tue, May 26, 2015 at 2:21 PM, Tim Dudgeon 

wrote:

Sorry, not clear on this. Where does the  element go?
The XML generated from the route looks like this:


http://camel.apache.org/schema/spring";>

  
  
  




The  element would normally be part of the spring XML, but

outside the

routes definition looking something like this:





http://camel.apache.org/schema/spring";>
  

  



Can the beans be defined in this way at runtime or is some other

mechanism

needed to instantiate the beans and add them to the registry

independently

of adding the route (as XML)?

Tim




On 26/05/2015 08:19, Claus Ibsen wrote:

Hi

Yeah 

On Tue, May 26, 2015 at 9:02 AM, Tim Dudgeon 
wrote:

Yes, but how to specify the bean that is referenced? Can that be
specified
in the XML using a bean element as if it was being using on startup,

or

does
it need to be added to the registry "manually"?

Tim


On 26/05/2015 07:49, Claus Ibsen wrote:

On Mon, May 25, 2015 at 3:01 PM, Tim Dudgeon 
wrote:

Hi,

I'm wanting some guidance on how to generate a route definition

using

the
API in a way that allows it to be converted to XML and then

executed.

I've
got the basics sorted, but struggling on how to handle processors

and

beans.
For instance, if I generate a route like this:

// generate the route
RoutesDefinition routes1 = new RoutesDefinition()
RouteDefinition route = routes1.route()
route.from("timer://foo?fixedRate=true&period=200")
route.log("Hello World!")
route.process(new SimpleProcessor())

// set route to context
CamelContext camelContext = new DefaultCamelContext()
camelContext.start()
camelContext.addRouteDefinitions(routes1.getRoutes())

Then the route works fine (e.g. my SimpleProcessor gets called as
expected).
But if I generate the XML definition of the route it looks like

this:


http://camel.apache.org/schema/spring";>







e.g. the processor definition has been lost.
I suspect I need to register the processor bean with the registry

and

use
the processRef() method on the route, or something along those

lines.

Does anyone have any examples of how to handle this?


Yes for representing this as xml, you would need to use a ref for the
processor




Thanks
Tim










Re: route <-> XML <-> route

2015-05-26 Thread Pontus Ullgren
Depending on the registry you use you can create the beans in java and add
them to the registry in runtime before you add (and start) the route in the
context.

I have some example code on how to do this using a spring registry. However
since you say you are not using spring you will have to figure out how to
add the beans programmatically to the registry implementation you are
using.

Best regards
Pontus

On Tue, 26 May 2015 16:28 Tim Dudgeon  wrote:

> The beans are defined at runtime, so can't go in the spring xml that is
> used on startup (and I'm not actually using spring, though could do if
> essential).
> I need to provide the route definition plus any beans it uses at
> runtime, after the context has started.
>
> Tim
>
> On 26/05/2015 15:23, Claus Ibsen wrote:
> > Hi
> >
> > If you are using spring xml then the beans need to go in the spring
> > xml file as .
> >
> > You may be able to add those beans later using some spring java api.
> >
> > On Tue, May 26, 2015 at 2:21 PM, Tim Dudgeon 
> wrote:
> >> Sorry, not clear on this. Where does the  element go?
> >> The XML generated from the route looks like this:
> >>
> >> 
> >> http://camel.apache.org/schema/spring";>
> >>
> >>  
> >>  
> >>  
> >> 
> >> 
> >>
> >>
> >> The  element would normally be part of the spring XML, but
> outside the
> >> routes definition looking something like this:
> >>
> >> 
> >> 
> >>
> >>
> >>http://camel.apache.org/schema/spring";>
> >>  
> >>
> >>  
> >>
> >> 
> >>
> >> Can the beans be defined in this way at runtime or is some other
> mechanism
> >> needed to instantiate the beans and add them to the registry
> independently
> >> of adding the route (as XML)?
> >>
> >> Tim
> >>
> >>
> >>
> >>
> >> On 26/05/2015 08:19, Claus Ibsen wrote:
> >>> Hi
> >>>
> >>> Yeah 
> >>>
> >>> On Tue, May 26, 2015 at 9:02 AM, Tim Dudgeon 
> >>> wrote:
>  Yes, but how to specify the bean that is referenced? Can that be
>  specified
>  in the XML using a bean element as if it was being using on startup,
> or
>  does
>  it need to be added to the registry "manually"?
> 
>  Tim
> 
> 
>  On 26/05/2015 07:49, Claus Ibsen wrote:
> > On Mon, May 25, 2015 at 3:01 PM, Tim Dudgeon 
> > wrote:
> >> Hi,
> >>
> >> I'm wanting some guidance on how to generate a route definition
> using
> >> the
> >> API in a way that allows it to be converted to XML and then
> executed.
> >> I've
> >> got the basics sorted, but struggling on how to handle processors
> and
> >> beans.
> >> For instance, if I generate a route like this:
> >>
> >> // generate the route
> >> RoutesDefinition routes1 = new RoutesDefinition()
> >> RouteDefinition route = routes1.route()
> >> route.from("timer://foo?fixedRate=true&period=200")
> >> route.log("Hello World!")
> >> route.process(new SimpleProcessor())
> >>
> >> // set route to context
> >> CamelContext camelContext = new DefaultCamelContext()
> >> camelContext.start()
> >> camelContext.addRouteDefinitions(routes1.getRoutes())
> >>
> >> Then the route works fine (e.g. my SimpleProcessor gets called as
> >> expected).
> >> But if I generate the XML definition of the route it looks like
> this:
> >>
> >> 
> >> http://camel.apache.org/schema/spring";>
> >> 
> >> 
> >> 
> >> 
> >> 
> >> 
> >>
> >> e.g. the processor definition has been lost.
> >> I suspect I need to register the processor bean with the registry
> and
> >> use
> >> the processRef() method on the route, or something along those
> lines.
> >> Does anyone have any examples of how to handle this?
> >>
> > Yes for representing this as xml, you would need to use a ref for the
> > processor
> >
> >
> >
> >> Thanks
> >> Tim
> >
> >
> >>>
> >
> >
>
>


Re: route <-> XML <-> route

2015-05-26 Thread Tim Dudgeon
The beans are defined at runtime, so can't go in the spring xml that is 
used on startup (and I'm not actually using spring, though could do if 
essential).
I need to provide the route definition plus any beans it uses at 
runtime, after the context has started.


Tim

On 26/05/2015 15:23, Claus Ibsen wrote:

Hi

If you are using spring xml then the beans need to go in the spring
xml file as .

You may be able to add those beans later using some spring java api.

On Tue, May 26, 2015 at 2:21 PM, Tim Dudgeon  wrote:

Sorry, not clear on this. Where does the  element go?
The XML generated from the route looks like this:


http://camel.apache.org/schema/spring";>
   
 
 
 




The  element would normally be part of the spring XML, but outside the
routes definition looking something like this:



   

   http://camel.apache.org/schema/spring";>
 
   
 
   


Can the beans be defined in this way at runtime or is some other mechanism
needed to instantiate the beans and add them to the registry independently
of adding the route (as XML)?

Tim




On 26/05/2015 08:19, Claus Ibsen wrote:

Hi

Yeah 

On Tue, May 26, 2015 at 9:02 AM, Tim Dudgeon 
wrote:

Yes, but how to specify the bean that is referenced? Can that be
specified
in the XML using a bean element as if it was being using on startup, or
does
it need to be added to the registry "manually"?

Tim


On 26/05/2015 07:49, Claus Ibsen wrote:

On Mon, May 25, 2015 at 3:01 PM, Tim Dudgeon 
wrote:

Hi,

I'm wanting some guidance on how to generate a route definition using
the
API in a way that allows it to be converted to XML and then executed.
I've
got the basics sorted, but struggling on how to handle processors and
beans.
For instance, if I generate a route like this:

// generate the route
RoutesDefinition routes1 = new RoutesDefinition()
RouteDefinition route = routes1.route()
route.from("timer://foo?fixedRate=true&period=200")
route.log("Hello World!")
route.process(new SimpleProcessor())

// set route to context
CamelContext camelContext = new DefaultCamelContext()
camelContext.start()
camelContext.addRouteDefinitions(routes1.getRoutes())

Then the route works fine (e.g. my SimpleProcessor gets called as
expected).
But if I generate the XML definition of the route it looks like this:


http://camel.apache.org/schema/spring";>







e.g. the processor definition has been lost.
I suspect I need to register the processor bean with the registry and
use
the processRef() method on the route, or something along those lines.
Does anyone have any examples of how to handle this?


Yes for representing this as xml, you would need to use a ref for the
processor




Thanks
Tim












Re: route <-> XML <-> route

2015-05-26 Thread Claus Ibsen
Hi

If you are using spring xml then the beans need to go in the spring
xml file as .

You may be able to add those beans later using some spring java api.

On Tue, May 26, 2015 at 2:21 PM, Tim Dudgeon  wrote:
> Sorry, not clear on this. Where does the  element go?
> The XML generated from the route looks like this:
>
> 
> http://camel.apache.org/schema/spring";>
>   
> 
> 
> 
> 
> 
>
>
> The  element would normally be part of the spring XML, but outside the
> routes definition looking something like this:
>
> 
> 
>   
>
>   http://camel.apache.org/schema/spring";>
> 
>   
> 
>   
> 
>
> Can the beans be defined in this way at runtime or is some other mechanism
> needed to instantiate the beans and add them to the registry independently
> of adding the route (as XML)?
>
> Tim
>
>
>
>
> On 26/05/2015 08:19, Claus Ibsen wrote:
>>
>> Hi
>>
>> Yeah 
>>
>> On Tue, May 26, 2015 at 9:02 AM, Tim Dudgeon 
>> wrote:
>>>
>>> Yes, but how to specify the bean that is referenced? Can that be
>>> specified
>>> in the XML using a bean element as if it was being using on startup, or
>>> does
>>> it need to be added to the registry "manually"?
>>>
>>> Tim
>>>
>>>
>>> On 26/05/2015 07:49, Claus Ibsen wrote:

 On Mon, May 25, 2015 at 3:01 PM, Tim Dudgeon 
 wrote:
>
> Hi,
>
> I'm wanting some guidance on how to generate a route definition using
> the
> API in a way that allows it to be converted to XML and then executed.
> I've
> got the basics sorted, but struggling on how to handle processors and
> beans.
> For instance, if I generate a route like this:
>
> // generate the route
> RoutesDefinition routes1 = new RoutesDefinition()
> RouteDefinition route = routes1.route()
> route.from("timer://foo?fixedRate=true&period=200")
> route.log("Hello World!")
> route.process(new SimpleProcessor())
>
> // set route to context
> CamelContext camelContext = new DefaultCamelContext()
> camelContext.start()
> camelContext.addRouteDefinitions(routes1.getRoutes())
>
> Then the route works fine (e.g. my SimpleProcessor gets called as
> expected).
> But if I generate the XML definition of the route it looks like this:
>
> 
> http://camel.apache.org/schema/spring";>
> 
> 
> 
> 
> 
> 
>
> e.g. the processor definition has been lost.
> I suspect I need to register the processor bean with the registry and
> use
> the processRef() method on the route, or something along those lines.
> Does anyone have any examples of how to handle this?
>
 Yes for representing this as xml, you would need to use a ref for the
 processor



> Thanks
> Tim



>>
>>
>



-- 
Claus Ibsen
-
Red Hat, Inc.
Email: cib...@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/


Re: route <-> XML <-> route

2015-05-26 Thread Tim Dudgeon

Sorry, not clear on this. Where does the  element go?
The XML generated from the route looks like this:


http://camel.apache.org/schema/spring";>
  







The  element would normally be part of the spring XML, but outside 
the routes definition looking something like this:




  

  http://camel.apache.org/schema/spring";>

  

  


Can the beans be defined in this way at runtime or is some other 
mechanism needed to instantiate the beans and add them to the registry 
independently of adding the route (as XML)?


Tim



On 26/05/2015 08:19, Claus Ibsen wrote:

Hi

Yeah 

On Tue, May 26, 2015 at 9:02 AM, Tim Dudgeon  wrote:

Yes, but how to specify the bean that is referenced? Can that be specified
in the XML using a bean element as if it was being using on startup, or does
it need to be added to the registry "manually"?

Tim


On 26/05/2015 07:49, Claus Ibsen wrote:

On Mon, May 25, 2015 at 3:01 PM, Tim Dudgeon 
wrote:

Hi,

I'm wanting some guidance on how to generate a route definition using the
API in a way that allows it to be converted to XML and then executed.
I've
got the basics sorted, but struggling on how to handle processors and
beans.
For instance, if I generate a route like this:

// generate the route
RoutesDefinition routes1 = new RoutesDefinition()
RouteDefinition route = routes1.route()
route.from("timer://foo?fixedRate=true&period=200")
route.log("Hello World!")
route.process(new SimpleProcessor())

// set route to context
CamelContext camelContext = new DefaultCamelContext()
camelContext.start()
camelContext.addRouteDefinitions(routes1.getRoutes())

Then the route works fine (e.g. my SimpleProcessor gets called as
expected).
But if I generate the XML definition of the route it looks like this:


http://camel.apache.org/schema/spring";>







e.g. the processor definition has been lost.
I suspect I need to register the processor bean with the registry and use
the processRef() method on the route, or something along those lines.
Does anyone have any examples of how to handle this?


Yes for representing this as xml, you would need to use a ref for the
processor




Thanks
Tim










Re: route <-> XML <-> route

2015-05-26 Thread Claus Ibsen
Hi

Yeah 

On Tue, May 26, 2015 at 9:02 AM, Tim Dudgeon  wrote:
> Yes, but how to specify the bean that is referenced? Can that be specified
> in the XML using a bean element as if it was being using on startup, or does
> it need to be added to the registry "manually"?
>
> Tim
>
>
> On 26/05/2015 07:49, Claus Ibsen wrote:
>>
>> On Mon, May 25, 2015 at 3:01 PM, Tim Dudgeon 
>> wrote:
>>>
>>> Hi,
>>>
>>> I'm wanting some guidance on how to generate a route definition using the
>>> API in a way that allows it to be converted to XML and then executed.
>>> I've
>>> got the basics sorted, but struggling on how to handle processors and
>>> beans.
>>> For instance, if I generate a route like this:
>>>
>>> // generate the route
>>> RoutesDefinition routes1 = new RoutesDefinition()
>>> RouteDefinition route = routes1.route()
>>> route.from("timer://foo?fixedRate=true&period=200")
>>> route.log("Hello World!")
>>> route.process(new SimpleProcessor())
>>>
>>> // set route to context
>>> CamelContext camelContext = new DefaultCamelContext()
>>> camelContext.start()
>>> camelContext.addRouteDefinitions(routes1.getRoutes())
>>>
>>> Then the route works fine (e.g. my SimpleProcessor gets called as
>>> expected).
>>> But if I generate the XML definition of the route it looks like this:
>>>
>>> 
>>> http://camel.apache.org/schema/spring";>
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>>
>>> e.g. the processor definition has been lost.
>>> I suspect I need to register the processor bean with the registry and use
>>> the processRef() method on the route, or something along those lines.
>>> Does anyone have any examples of how to handle this?
>>>
>> Yes for representing this as xml, you would need to use a ref for the
>> processor
>>
>>
>>
>>> Thanks
>>> Tim
>>
>>
>>
>



-- 
Claus Ibsen
-
Red Hat, Inc.
Email: cib...@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/


Re: route <-> XML <-> route

2015-05-26 Thread Tim Dudgeon
Yes, but how to specify the bean that is referenced? Can that be 
specified in the XML using a bean element as if it was being using on 
startup, or does it need to be added to the registry "manually"?


Tim

On 26/05/2015 07:49, Claus Ibsen wrote:

On Mon, May 25, 2015 at 3:01 PM, Tim Dudgeon  wrote:

Hi,

I'm wanting some guidance on how to generate a route definition using the
API in a way that allows it to be converted to XML and then executed. I've
got the basics sorted, but struggling on how to handle processors and beans.
For instance, if I generate a route like this:

// generate the route
RoutesDefinition routes1 = new RoutesDefinition()
RouteDefinition route = routes1.route()
route.from("timer://foo?fixedRate=true&period=200")
route.log("Hello World!")
route.process(new SimpleProcessor())

// set route to context
CamelContext camelContext = new DefaultCamelContext()
camelContext.start()
camelContext.addRouteDefinitions(routes1.getRoutes())

Then the route works fine (e.g. my SimpleProcessor gets called as expected).
But if I generate the XML definition of the route it looks like this:


http://camel.apache.org/schema/spring";>







e.g. the processor definition has been lost.
I suspect I need to register the processor bean with the registry and use
the processRef() method on the route, or something along those lines.
Does anyone have any examples of how to handle this?


Yes for representing this as xml, you would need to use a ref for the processor




Thanks
Tim







Re: route <-> XML <-> route

2015-05-25 Thread Claus Ibsen
On Mon, May 25, 2015 at 3:01 PM, Tim Dudgeon  wrote:
> Hi,
>
> I'm wanting some guidance on how to generate a route definition using the
> API in a way that allows it to be converted to XML and then executed. I've
> got the basics sorted, but struggling on how to handle processors and beans.
> For instance, if I generate a route like this:
>
> // generate the route
> RoutesDefinition routes1 = new RoutesDefinition()
> RouteDefinition route = routes1.route()
> route.from("timer://foo?fixedRate=true&period=200")
> route.log("Hello World!")
> route.process(new SimpleProcessor())
>
> // set route to context
> CamelContext camelContext = new DefaultCamelContext()
> camelContext.start()
> camelContext.addRouteDefinitions(routes1.getRoutes())
>
> Then the route works fine (e.g. my SimpleProcessor gets called as expected).
> But if I generate the XML definition of the route it looks like this:
>
> 
> http://camel.apache.org/schema/spring";>
> 
> 
> 
> 
> 
> 
>
> e.g. the processor definition has been lost.
> I suspect I need to register the processor bean with the registry and use
> the processRef() method on the route, or something along those lines.
> Does anyone have any examples of how to handle this?
>

Yes for representing this as xml, you would need to use a ref for the processor



> Thanks
> Tim



-- 
Claus Ibsen
-
Red Hat, Inc.
Email: cib...@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/