4 Replies Latest reply on Mar 13, 2012 12:34 PM by Ja kub

    osgi service without restart of projects referencing it

    Ja kub Novice

      I am a newbie at camel and service mix osgi and I have a simple question


      is it possible to configure






      so as when bundle with osgi:service is restarted bundles with osgi:reference with it's bean-name wouldn't be restarted?


      Now when bundle exposing service is restarted bundles using it are also automatically restarted, I would like to avoid it.

      I am using service mix with spring and camel.


      Maybe there is a way to prevent service mix from restarting?



      Thanks for Your help,


        • 1. Re: osgi service without restart of projects referencing it
          Freeman(Yue) Fang Master



          I don't think so.

          And why you need it?


          If the service exposing bundle restart, it means the old service it exposed is gone so if the service reference bundle not restart/refresh at the same time, it will cause the service reference bundle doesn't work correctly as it still hold the invalid service reference.


          However, I think you can just update the service exposing bundle, this by default will not cause any bundle refresh/restart.



          • 2. Re: osgi service without restart of projects referencing it
            Ja kub Novice

            We want to get rid of nmr, to be able to use camel standalone without servicemix, as far as I know nmr cannot be used without servicemix. If direct: would work across bundles It would be the best, but direct: doesn't work across bundles.


            I want to be able to communicate across bundles. Now we use nmr to communicate across bundles. We replace nmr with osgi service exposed by the target bundle:


                private Map<String, String> routeMap;



                protected ProducerTemplate producer;


                private CamelContext camelContext;



                public void setCamelContext(CamelContext camelContext) {

                    this.camelContext = camelContext;




                public CamelContext getCamelContext() {

                    return camelContext;




                   public void process(Exchange exchange) throws Exception {


                    String serviceQName = extractServiceQName(exchange);

                    String uri = routeMap.get(serviceQName);


                    CamelContext callerContext = exchange.getContext();


                    setExchangeContext(exchange, camelContext);


                    producer.send(uri, exchange);


                    setExchangeContext(exchange, callerContext);




            possibly  cardinality="0..1"->  http://static.springsource.org/osgi/docs/1.2.1/reference/html/service-registry.html#service-registry:refs:singular:cardinality    will solve my problem

            • 3. Re: osgi service without restart of projects referencing it
              Claus Ibsen Master

              People have been using the Camel VM component to communicate across bundles. But note that the VM component was originally not designed for OSGi communication.


              OSGi bundles can also communicate directly using OSGi services, so you can export a bean into the OSGi service registry, and then reference that bean from another bundle, and then use that bean.


              Then you can use the  in Camel routes to access this bean, and communicate between bundles.

              • 4. Re: osgi service without restart of projects referencing it
                Ja kub Novice

                cardinality="0..1" was what I needed


                Thans All for help,