You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Claus Ibsen <cl...@gmail.com> on 2013/03/01 10:40:15 UTC

Re: camel and several implementations of an interface

On Thu, Feb 28, 2013 at 3:42 PM, Smith-John <mi...@gmail.com> wrote:
> Having a bundle with an interface and several implementations of it (all in
> their own bundle), how can I decide which bundle to call?
>
> Details:
> Bundle 1 just defines an interface. (packageName.InterfaceName)
> Bundle 2, 3 & 4 implement this interface.
>
> Problem is, with
>  .to("bean:packageName.InterfaceName?method=doIt")
> I just can set the interface. But how to decide which concrete
> implementation to call?
>
> (Working with Equinox)
>

The Camel osgi service registry from camel-core-osgi
(OsgiServiceRegistry) does not support that osgi ldap filter syntax,
so you cannot use that filter to select which impl to use.

You may need to do this manually using OSGi API and call the bean yourself.

Or if you use some spring-dm or osgi blueprint xml file, you can make
a <reference> in the XML and then Camel can use that reference as is
with the bean component.

>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/camel-and-several-implementations-of-an-interface-tp5728298.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: camel and several implementations of an interface

Posted by Smith-John <mi...@gmail.com>.
Isn't there a way in camel to call a concrete osgi-service/bundle?
I'm working with declarative services, so the bundles could be bound anyway
somewhere. 



--
View this message in context: http://camel.465427.n5.nabble.com/camel-and-several-implementations-of-an-interface-tp5728298p5728378.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel and several implementations of an interface

Posted by Smith-John <mi...@gmail.com>.
Camel ist started with

OsgiServiceRegistry reg = new OsgiServiceRegistry(bundleContext);
OsgiDefaultCamelContext camelContext = new
OsgiDefaultCamelContext(bundleContext, reg);
camelContext.addRoutes(new Route());
camelContext.start();



--
View this message in context: http://camel.465427.n5.nabble.com/camel-and-several-implementations-of-an-interface-tp5728298p5728358.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel and several implementations of an interface

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Mar 1, 2013 at 1:52 PM, Smith-John <mi...@gmail.com> wrote:
> In one of the plugin bundles (that implements the interface) I added in
> OSGI-INF/blueprint a xml file with
>
> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
>    <service id="pluginOne" ref="mockUp"
>     interface="pluginInterface.PluginInterface" />
>    <bean id="mockUp" class="pluginMock.PluginMock" />
> </blueprint>
>
> and to the bundle containing camel context and the route in which I want to
> call the mentioned plugin I put
>
> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
>    <reference id="mockup" interface="pluginInterface.PluginInterface"/>
> </blueprint>
>
> But .to("bean:mockup") throws
> org.apache.camel.NoSuchBeanException: No bean could be found in the registry
> for: mockup.
>
> Dont't know where the mistake is.
> camel-blueprint & aries-blueprint bundles are added to run config.
>
> The goal is to get a plugin system, where you can start bundles during
> runtime and use them.
>

How do you create and start Camel in your bundle?

You do not embed <camelContext> in your blueprint XML file?
If not then you need to setup Camel in OSGi / blueprint.

There should be a BlueprintCamelContext or something you should use then.

As there is some osgi logic needed to hook into the osgi service
registry when Camel does bean lookups.
All that stuff is done for you when using <camelContext>

>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/camel-and-several-implementations-of-an-interface-tp5728298p5728353.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: camel and several implementations of an interface

Posted by Smith-John <mi...@gmail.com>.
In one of the plugin bundles (that implements the interface) I added in
OSGI-INF/blueprint a xml file with

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
   <service id="pluginOne" ref="mockUp"
    interface="pluginInterface.PluginInterface" />
   <bean id="mockUp" class="pluginMock.PluginMock" />
</blueprint> 

and to the bundle containing camel context and the route in which I want to
call the mentioned plugin I put

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
   <reference id="mockup" interface="pluginInterface.PluginInterface"/>
</blueprint>

But .to("bean:mockup") throws
org.apache.camel.NoSuchBeanException: No bean could be found in the registry
for: mockup.

Dont't know where the mistake is.
camel-blueprint & aries-blueprint bundles are added to run config.

The goal is to get a plugin system, where you can start bundles during
runtime and use them.



--
View this message in context: http://camel.465427.n5.nabble.com/camel-and-several-implementations-of-an-interface-tp5728298p5728353.html
Sent from the Camel - Users mailing list archive at Nabble.com.