It's no secret that the OSGI Blueprint implements a proxy object for the
service. In the old specification OSGI used references to objects.
Very often forget to let go of the service object obtained from the
ServiseReference.
For this reason, it is desirable to use the links provided in the blueprint.
Camel process can be described in a blueprint xml file. But it is not always
convenient. In particular, all of the components (bean) should be in the
open part of the osgi bundle.
Using a public method, referring to the components of the private part of
the osgi bundle is very bad. BIND swears by these methods.
There is only one. We must use the Java DSL Builder process.

<reference id="externalService" interface="external.ExternalService"/>

<bean id="routeBuilder" class="publicpackage.LocalRouteBuilder"/>
  
<camelContext id="camel-ccje-exchange-oos-doc-read"
xmlns="http://camel.apache.org/schema/blueprint";>
  <propertyPlaceholder id="properties" location="blueprint:placeholder"/>
  <routeBuilder ref="routeBuilder"/>
</camelContext>

Inside RouteBuilder can use annotations @ PropertyInject, @ EndpointInject.
But to get service "externalService" can only be the old-fashioned

import external.ExternalService;
import privatepackage.MyBean;

public class LocalRouteBuilder extends RouteBuilder {
   public void configure() throws Exception {
      ExternalService externalService =
CamelContextHelper.mandatoryLookup(getContext(), "externalService",
ExternalService.class);
      MyBean bean = new MyBean(externalService);

      from("direct.start)
        .bean(bean, "doProcess")
      .end();
   }
}

Similarly, it was possible to get any property

String value = CamelContextHelper.parseText(getContext(),
"{{my_property}}");

or through annotation

@PropertyInject ("my_property") String value;


I propose to add an annotation @BeanInject

import external.ExternalService;
import privatepackage.MyBean;

public class LocalRouteBuilder extends RouteBuilder {
   @BeanInject(ref="externalService") ExternalService externalService;

   public void configure() throws Exception {
      MyBean bean = new MyBean(externalService);

      from("direct.start)
        .bean(bean, "doProcess")
      .end();
   }
}

In the blueprint and in spring you can pass all the components as properties
or constructor parameters.
This can be done in Guice, jndi, JUnit.

I am at the project using the OSGI blueprint for services and management
Camel processes. Inside guice for working with MyBatis, not to show the
private part of the OSGI bundle.

By the way. There is one nice little bug.
@Produce and @EndpointInject perform the same action in
DefaultCamelBeanPostProcessor.
We expect that the implementation of the @Produce is ProducerTemplate or
Producer. We can get ConsumerTemplate, PollingConsumer, Endpoint.

@Produce(url="direct.start")
ConsumerTemplate consumer; // raze it right?




--
View this message in context: 
http://camel.465427.n5.nabble.com/Propose-add-annotation-BeanInject-tp5742782.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to