Hi
Camel is a client that lookup in an existing registry you use, eg
Spring App Context, CDI, Guice, OSGi Service Registry, JNDI, or
whatever you may write as custom registry.
Camel comes with a few out of the box, JndiRegistry, SimpleRegistry.
So if you want to use a registry where you can add/bind your own
beans, then use one of these and pass it to the constructor of the
DefaultCamelContext
SimpleRegistry reg = new SimpleRegistry()
reg.put("foo", new FooBean());
CamelContext camel = new DefaultCamelContext(reg);
We cannot have a bind/put method on the registry api, as Camel is
registry agnostic and uses it as a client, where we can only lookup in
the registry.
On Mon, Mar 18, 2013 at 10:03 AM, Sven Bauhan <[email protected]> wrote:
> Hi,
>
> I think for the interface Registry a method bind() should be defined. Here
> comes the explanation why:
>
> Finally I managed to create a camel context component to put a route in a
> black box. But I want to put this context component into a library and hide
> it behind an API.
>
> Starting point was the description in http://camel.apache.org/context.html
> and the detailed example in
> http://svn.apache.org/viewvc/camel/trunk/components/camel-context/src/test/java/org/apache/camel/component/context/JavaDslBlackBoxTest.java?revision=1069442&view=markup
>
> In the given example, the blackbox is not put in a separate library. But if
> I put it in a library it looks this way:
>
> public class ContextComponent {
> public static CamelContext createContext() throws Exception {
> DefaultCamelContext atsm_context = new DefaultCamelContext();
> atsm_context.setName("ATSM");
> atsm_context.addRoutes(new ContextRouteBuilder());
> atsm_context.start();
> return atsm_context;
> }
> }
>
> public class ATSMTest extends CamelTestSupport {
>
> @Override
> protected JndiRegistry createRegistry() throws Exception {
> JndiRegistry registry = super.createRegistry();
> CamelContext atsm_context = ContextComponent.createContext();
> registry.bind("atsm", atsm_context);
> return registry;
> }
>
> @Override
> protected RouteBuilder createRouteBuilder() throws Exception {
> return new RouteBuilder() {
>
> @Override
> public void configure() throws Exception {
> ...
> }
> };
> }
>
> @Test
> public void TestRoute() throws Exception {
> ...
> }
> }
>
> The drawback here is, that the registry binding has to be done in the
> application not in the library.
>
> I tried to give the registry reference to the createContext( Registry
> registry), to call the bind() method. But then I have to cast the registry
> to JndiRegistry, to call bind(). So this would only work if the application
> uses a JndiRegistry.
> If the interface Registry would define a bind() method, this would work for
> all registry kinds.
> (For SimpleRegistry the bind() method have to call put() internally).
>
> Is my idea correct or would this lead to other problems?
>
> Thanks, Sven
>
--
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: [email protected]
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen