javaapache-camelosgiblueprint-osgi

Is it possible to outhouse ShutdownStrategy for CamelContext into a central OSGi bundle?


I am trying to outhouse central beans of my OSGi bundles into a central bundle, which provides them as a service. This works fine with the ErrorHanlders and Processors, but not with the ShutdownStrategy and RedeliveryPolicy. The Error Message I receive is

org.osgi.service.blueprint.container.ComponentDefinitionException: A class org.apache.camel.processor.RedeliveryPolicy was found in the interfaces list, but class proxying is not allowed by default. The ext:proxy-method='classes' attribute needs to be added to this service reference.

I could try to follow the instrutction and add the ext:proxy-method, but first I want to understand the clue here. Maybe it's not a good idea to centralize strategies and policies?

[EDIT] The mistake here was to use the class in the service instead of an interface. So interface="org.apache.camel.spi.ShutdownStrategy" should be the correct Interface here (for the ShutdownStrategy). The bundle with my camel route references this service so:

<reference
    id="shutdownStrategy"
    interface="org.apache.camel.spi.ShutdownStrategy"
    component-name="shutdownStrategy" />

But now I get the following error:

java.lang.IllegalArgumentException: CamelContext must be specified

[EDIT] I want to confine this question to the ShutdownStrategy, because the RedeliveryPolicy works fine when I referenc it in the ErrorHandlers inside my central bundle.

So is it possible to outhouse the ShutdownStrategy, too? Maybe not, because it needs a CamelContext.

When using Spring XML you then just define a spring bean which implements the org.apache.camel.spi.ShutdownStrategy and Camel will look it up at startup and use it instead of its default.


Solution

  • I found the answer in the Camel documentation

    You can implement your own strategy to control the shutdown by implementing the org.apache.camel.spi.ShutdownStrategy and the set it on the CamelContext using the setShutdownStrategy method.

    When using Spring XML you then just define a spring bean which implements the org.apache.camel.spi.ShutdownStrategy and Camel will look it up at startup and use it instead of its default.

    So if you have your own implementation of the ShutdownStrategy you can use it as a bean.

    <bean id="shutdownStrategy"
        class="org.apache.camel.spi.ShutdownStrategy">
    </bean>