You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by dermoritz <ta...@hotmail.com> on 2014/07/11 11:24:43 UTC

Problem injecting CamelContext within RouteBuilder - using guice

I created an camel standalone app that is using google guice. i am not using
camel-guice (found it to late) so this is how i use it:
I extended org.apache.camel.main.Main:

public final class OurMain extends Main {

    /**
     * Context to be injected - contains complete setup.
     */
    @Inject
    private CamelContext context;

    @Override
    protected CamelContext createContext() {
        return context;
    }
}

And here is my main:
    public static void main(final String... args) throws Exception {
        Injector i = Guice.createInjector(new CepModule());
        OurMain main = i.getInstance(OurMain.class);
        main.enableHangupSupport();
        main.run();
    }

In module has a provider for CamelContext where i create a default context
and add a the RouteBuilder. This RouteBuilder is injecting other
RoutBuilders and all the other stuff.

My Problem is that i cant inject the context within RouteBuilder or other
classes that RoutBuilder is using because this results in circular
dependency Context injects RouteBuilder injects Context does not work.

Sometimes i need to create general endpoints to be reused in some of the
routebuilders. Like a throughput logger:
   
    @Provides
    @Named("TPLogger")
    @Inject
    private final Endpoint getTPLogger(CamelContext context){
        LogEndpoint endpoint = context.getEndpoint("log:",
LogEndpoint.class);
        endpoint.setGroupInterval(new Long(10000));
        endpoint.setGroupActiveOnly(false);
        return endpoint;
    } 
   
But this isn't working. So is there a way to inject the context probably by
using camel-guice (is there an example on using camel-guice with guice' Main
- my frist tries failed)?
Or is there another way to create specific endpoints?




--
View this message in context: http://camel.465427.n5.nabble.com/Problem-injecting-CamelContext-within-RouteBuilder-using-guice-tp5753707.html
Sent from the Camel - Users mailing list archive at Nabble.com.