activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Gunther <jeff.gunt...@intalgent.com>
Subject Re: [camel] Spring and Custom Components
Date Thu, 10 May 2007 15:59:24 GMT
Hi James,

Thank you for the very detailed follow up! That worked wonderfully.  
Related to this issue, how would I set the ConnectionFactory for the  
JMS Component?

Jeff Gunther

On May 10, 2007, at 11:27 AM, James Strachan wrote:

> Hi Jeff
>
> On 5/9/07, Jeff Gunther <Jeff.Gunther@intalgent.com> wrote:
>> Hi All,
>>
>> Here is the code snippet I'm working to configure in Spring:
>>
>> final CamelContext container = new DefaultCamelContext();
>> container.addComponent("foo", new FooComponent(container));
>
> FWIW if you don't need to explicitly configure the FooComponent
> directly if it doesn't have much configuration data - you can create a
> file called
>
> /META-INF/services/org/apache/camel/component/foo
>
> with contents
>
> class=org.acme.FooComponent
>
> (you can add other property configurations in there too if you like)
>
> Then if you refer to an endpoint as "foo://somethingOrOther" Camel
> will auto-discover your component and register it.
>
> The downside of this approach though is if FooComponent needs some
> actual injection; like a DataSource or whatever. You can configure
> endpoints in a few different ways...
> http://cwiki.apache.org/CAMEL/how-do-i-configure-endpoints.html
>
>
> One thing thats not quite tested or documented yet that I wanted was
> the ability to use the Injector on a CamelContext to dependency inject
> the FooComponent (using either autowire mode in Spring or using
> @Resource type dependency injection) so that you don't have to
> explicitly add the FooComponent to the Spring XML, you just need to
> add the resources which need to be injected into the FooComponent.
> (This also has the nice benefit of avoiding component developers
> having to worry about writing Spring XML namespace handler stuff)
>
>
>> I'm using the Spring 2.0 XML Namespaces approach to define my routes.
>> How can I add a custom component to a "camelContext"?
>
> If after my long ramble above you still want to explicitly have a
> <fooComponent cheese="edam"/> type XML within the <camelContext/> then
> you need to do some Spring XML NamespaceHandler hacking - which is
> kinda ugly & crufty work unfortunately. You could use xbean-spring
> which tries to automate most of this work for you.
>
> If you look in camel-spring at CamelNamespaceHandler you'll see how we
> handle the Spring XML stuff (warning its kinda hairy code to look at).
> If you wanted <fooComponent> to be a standard part of the core Camel
> schema then you'd hack that file to add your component & add a patch
> to the camel XSD. Otherwise you could write your own namespace &
> schema if you prefer.
>
>
> Incidentally I've updated the website with more details
> http://cwiki.apache.org/CAMEL/how-do-i-add-a-component.html
> http://cwiki.apache.org/CAMEL/writing-components.html
> -- 
> James
> -------
> http://macstrac.blogspot.com/


Mime
View raw message