You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by unmarshall <un...@gmail.com> on 2010/11/09 11:48:34 UTC

Custom component Vs Custom processor

Hi All,

I have a very basic question. When do you decide to create a custom
component Vs creating a custom processor. A camel component implementation
has a processor either in terms of producer or consumer or both.

The question arose when i looked at the XSLT component. XsltComponent class
internally uses a processor (XsltBuilder) which then creates and returns a
special endpoint ProcessorEndpoint. What was the reasoning that went behind
making it a component instead of direct implementation of a Processor
interface.

You can still set xmlConverter, uriResolver properties on a Processor and
still will not have any state.

Best Regards,
Madhav
-- 
View this message in context: http://camel.465427.n5.nabble.com/Custom-component-Vs-Custom-processor-tp3256585p3256585.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Custom component Vs Custom processor

Posted by James Strachan <ja...@gmail.com>.
On 9 November 2010 10:48, unmarshall <un...@gmail.com> wrote:
> Hi All,
>
> I have a very basic question. When do you decide to create a custom
> component Vs creating a custom processor. A camel component implementation
> has a processor either in terms of producer or consumer or both.
>
> The question arose when i looked at the XSLT component. XsltComponent class
> internally uses a processor (XsltBuilder) which then creates and returns a
> special endpoint ProcessorEndpoint. What was the reasoning that went behind
> making it a component instead of direct implementation of a Processor
> interface.
>
> You can still set xmlConverter, uriResolver properties on a Processor and
> still will not have any state.

I'd even argue that thanks to the nice Bean integration that abstracts
away most Camel specific APIs...
http://camel.apache.org/bean-binding.html

I'd recommend either writing a Component or just using a bean (which
makes it easier and more natural to use Camel's type conversion etc)..


For me the decision comes down to

* do you want producers and consumers of your thing? If so that sounds
like a Component / Endpoint to me. If literally its just a method call
then maybe a bean is more natural - unless...

* does a URI scheme feel a natural way to refer to different endpoints
and configure your thing?

If so using a Component/Endpoint might be a good fit.

e.g. most XSLT transformations are usually the same, bar the odd
parameter here or there, usually the only thing that changes is the
URI of the template. So using a URI of "xslt:someTransform.xsl" feels
much more natural to Camel - its then trivial for someone to also use
"xslt:myOtherTransform.xsl" or even
"xslt:http://foo.com/something.xsl" without having to write a new bean
or figure out some class library configuration to take someone else's
bean and configure it using dependency injection.

If your bean is very complex with quite hairy dependency injection
requirements, then maybe a bean is easier; though even in that case,
you could take one specific complex configuration and make it a
Component then have multiple Endpoints hanging off it. (e.g. JMS is
complex configuration; you might make one JMS component for
WebSphereMQ with a specific JMS ConnectionFactory and another for
ActiveMQ then you've an easy URI to use to refer to queues & topics on
each).

So maybe it boils down to, can you see a useful way to represent your
thing as a set of URIs; if so Component/Endpoint makes sense. If its
only ever going to a very specific thing you invoke in the middle of a
route, a bean sounds fine though.

-- 
James
-------
FuseSource
Email: james@fusesource.com
Web: http://fusesource.com
Twitter: jstrachan
Blog: http://macstrac.blogspot.com/

Open Source Integration

Re: Custom component Vs Custom processor

Posted by unmarshall <un...@gmail.com>.
Hi James/Clause,

Thanks for your comments. Well i get the picture now. The confusion was
essentially because everything is eventually a Processor :)

Thanks again.

Best Regards,
Madhav


Claus Ibsen-2 wrote:
> 
> On Wed, Nov 10, 2010 at 12:24 PM, unmarshall <un...@gmail.com> wrote:
>>
>> Hi Richard,
>>
>> Thanks for your comment. I agree with your argument however i can very
>> easily implement a custom processor and use it for multiple routes. A
>> component internally calls a processor in the form of Consumer/Producer
>> attached to an endpoint.
>>
>> So again if i look at the XSLT component i feel that a custom processor
>> would have done that as well and could have been reused. So you already
>> have
>> XsltBuilder (processor) which is directly used from inside the xslt
>> component. Apart from using that processor it does nothing much. So that
>> raises the question again in my head as to when to create a component and
>> when not to.
>>
> 
> A component allows you to abstract at a higher level and you can use
> endpoints to leverage the component.
> So you can just send the message to an endpoint with an URI String.
> 
> A custom processor you cannot do this.
> 
> In the end user what suits you best :)
> 
> 
> 
>> Best Regards,
>> Madhav
>>
>>
>> Richard Kettelerij wrote:
>>>
>>> I've discussed the choice between components and processors earlier in
>>> http://camel.465427.n5.nabble.com/How-to-handle-firefox-outputting-files-as-component-td3047751.html#a3047804
>>> (second message).
>>>
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/Custom-component-Vs-Custom-processor-tp3256585p3258487.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
> 
> 
> 
> -- 
> Claus Ibsen
> -----------------
> FuseSource
> Email: cibsen@fusesource.com
> Web: http://fusesource.com
> Twitter: davsclaus
> Blog: http://davsclaus.blogspot.com/
> Author of Camel in Action: http://www.manning.com/ibsen/
> 
> 

-- 
View this message in context: http://camel.465427.n5.nabble.com/Custom-component-Vs-Custom-processor-tp3256585p3258618.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Custom component Vs Custom processor

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Nov 10, 2010 at 12:24 PM, unmarshall <un...@gmail.com> wrote:
>
> Hi Richard,
>
> Thanks for your comment. I agree with your argument however i can very
> easily implement a custom processor and use it for multiple routes. A
> component internally calls a processor in the form of Consumer/Producer
> attached to an endpoint.
>
> So again if i look at the XSLT component i feel that a custom processor
> would have done that as well and could have been reused. So you already have
> XsltBuilder (processor) which is directly used from inside the xslt
> component. Apart from using that processor it does nothing much. So that
> raises the question again in my head as to when to create a component and
> when not to.
>

A component allows you to abstract at a higher level and you can use
endpoints to leverage the component.
So you can just send the message to an endpoint with an URI String.

A custom processor you cannot do this.

In the end user what suits you best :)



> Best Regards,
> Madhav
>
>
> Richard Kettelerij wrote:
>>
>> I've discussed the choice between components and processors earlier in
>> http://camel.465427.n5.nabble.com/How-to-handle-firefox-outputting-files-as-component-td3047751.html#a3047804
>> (second message).
>>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Custom-component-Vs-Custom-processor-tp3256585p3258487.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: Custom component Vs Custom processor

Posted by unmarshall <un...@gmail.com>.
Hi Richard,

Thanks for your comment. I agree with your argument however i can very
easily implement a custom processor and use it for multiple routes. A
component internally calls a processor in the form of Consumer/Producer
attached to an endpoint.

So again if i look at the XSLT component i feel that a custom processor
would have done that as well and could have been reused. So you already have
XsltBuilder (processor) which is directly used from inside the xslt
component. Apart from using that processor it does nothing much. So that
raises the question again in my head as to when to create a component and
when not to.

Best Regards,
Madhav


Richard Kettelerij wrote:
> 
> I've discussed the choice between components and processors earlier in
> http://camel.465427.n5.nabble.com/How-to-handle-firefox-outputting-files-as-component-td3047751.html#a3047804
> (second message).
> 

-- 
View this message in context: http://camel.465427.n5.nabble.com/Custom-component-Vs-Custom-processor-tp3256585p3258487.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Custom component Vs Custom processor

Posted by Richard Kettelerij <ri...@gmail.com>.
I've discussed the choice between components and processors earlier in
http://camel.465427.n5.nabble.com/How-to-handle-firefox-outputting-files-as-component-td3047751.html#a3047804
(second message).


-- 
View this message in context: http://camel.465427.n5.nabble.com/Custom-component-Vs-Custom-processor-tp3256585p3256659.html
Sent from the Camel - Users mailing list archive at Nabble.com.