camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Quinn Stevenson <qu...@pronoia-solutions.com>
Subject Re: Invoking Dynamic OSGi Blueprint services from a Java RouteBuilder
Date Wed, 27 Jan 2016 20:25:19 GMT
I’m not using the annotations, but it sounds like the same issue.

I tried something else that seems to work - if I use the Bean Component ( http://camel.apache.org/bean.html
<http://camel.apache.org/bean.html> ), everything seems to be working as I’d expect.

So if I change my RouteBuilder to look like this:
public class BeanComponentBuilder extends RouteBuilder {
    Logger log = LoggerFactory.getLogger(this.getClass());

    String blueprintServiceReferenceId;

    @Override
    public void configure() throws Exception {
        from("timer://bean-component-builder?period=5000")
                .setBody( simple( "${exchangeProperty[" + Exchange.TIMER_FIRED_TIME + "]}")
)
                .log("Calling Service via Reference: ${body}" )
                .toF( "bean:%s?cache=%b", blueprintServiceReferenceId, false )
                .log("Finished" )
                .to( "mock://result");
    }

    public String getBlueprintServiceReferenceId() {
        return blueprintServiceReferenceId;
    }

    public void setBlueprintServiceReferenceId(String blueprintServiceReferenceId) {
        this.blueprintServiceReferenceId = blueprintServiceReferenceId;
    }
}

And my Blueprint to look like this:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
           xsi:schemaLocation="
       http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
       http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd"
>
    <reference id="echo-service" interface="com.pronoia.test.osgi.service.Echo" filter="instance=one"
timeout="2000" />

    <bean id="bean-component-builder" class="com.pronoia.test.camel.builder.impl.BeanComponentBuilder">
        <property name="blueprintServiceReferenceId" value="echo-service" />
    </bean>

    <camelContext id="bean-component-context" xmlns="http://camel.apache.org/schema/blueprint">
        <routeBuilder ref="bean-component-builder" />
    </camelContext>

</blueprint>

It seems to work as I’d expect.

However, if I inject the service reference into the RouteBuilder at all, the dynamic behavior
is broken. 

If I change my RouteBuiler to look like this:
public class BeanComponentBuilder extends RouteBuilder {
    Logger log = LoggerFactory.getLogger(this.getClass());

    String blueprintServiceReferenceId;

    Echo dummyServiceReference;

    @Override
    public void configure() throws Exception {
        from("timer://bean-component-builder?period=5000")
                .setBody( simple( "${exchangeProperty[" + Exchange.TIMER_FIRED_TIME + "]}")
)
                .log("Calling Service via Reference: ${body}" )
                .toF( "bean:%s?cache=%b", blueprintServiceReferenceId, false )
                .log("Finished" )
                .to( "mock://result");
    }

    public String getBlueprintServiceReferenceId() {
        return blueprintServiceReferenceId;
    }

    public void setBlueprintServiceReferenceId(String blueprintServiceReferenceId) {
        this.blueprintServiceReferenceId = blueprintServiceReferenceId;
    }

    public Echo getDummyServiceReference() {
        return dummyServiceReference;
    }

    public void setDummyServiceReference(Echo dummyServiceReference) {
        this.dummyServiceReference = dummyServiceReference;
    }

}

And my Blueprint to look like this:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
           xsi:schemaLocation="
       http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
       http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd"
>
    <reference id="echo-service" interface="com.pronoia.test.osgi.service.Echo" filter="instance=one"
timeout="2000" />

    <bean id="bean-component-builder" class="com.pronoia.test.camel.builder.impl.BeanComponentBuilder">
        <property name="blueprintServiceReferenceId" value="echo-service" />
        <property name="dummyServiceReference" ref="echo-service" />
    </bean>

    <camelContext id="bean-component-context" xmlns="http://camel.apache.org/schema/blueprint">
        <routeBuilder ref="bean-component-builder" />
    </camelContext>

</blueprint>
All that’s different between the two is the reference to the service is injected into the
route builder - but it’s never used.

Quinn Stevenson


> On Jan 27, 2016, at 10:32 AM, Ranx <brad.johnson@mediadriver.com> wrote:
> 
> This is serendipitous as I've recently run into this as well.  I switched
> from straight Blueprint routes and instantiation to using blueprint to
> bootstrap the routebuilder(s).  But the injection of the reference to the
> service from blueprint doesn't appear to be proxied as I see the concrete
> class and the hot swapping isn't working as expected.
> 
> If I'm understanding this correctly it doesn't matter if the route builder
> is bootstrapped through blueprint it is still going to use the simple
> registry mechanics instead of the OSGi service registry.  In bundle A I have
> blueprint that looks like:
> 
> 	<service interface="my.services.api.InvoiceDocumentService">
> 		<bean class="my.services.test.internal.TestInvoiceServiceImpl" />
> 	</service>
> 
> In bundle B I have this startup.
> 	<camelContext xmlns="http://camel.apache.org/schema/blueprint">
> 		<package>my.routes.internal</package>
> 	</camelContext>
> 
> In the routes package I have an @BeanInject for the
> my.services.api.InvoiceDocumentService.  They live in different bundles and
> the internals are not exported.  But when I do a .getClass().getName on the
> service api received in bundle B it shows the implementation class.  I don't
> believe that's the proxy class.
> 
> So it appears that using this mechanic is skirting the OSGi service proxying
> mechanism.  Is that a correct assessment?
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/Invoking-Dynamic-OSGi-Blueprint-services-from-a-Java-RouteBuilder-tp5776755p5776848.html
> Sent from the Camel - Users mailing list archive at Nabble.com.


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message