Register a OSGI service and get that OSGI service refrence using WSO2 Product

1.1k views Asked by At

Actually i want to migrate my application from FUSE ESB to WSO2esb. In my FUSE application, i have created a OSGI bundle for Logger and register Logger service in OSGI registry.Other OSGI bundle can get that OSGI service through reference of it.

I have created one OSGI maven Project for Logger using servicemix-camel-osgi artifactId. I've using Apache Camel Approach so created one MainRoute xml file.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:camel="http://camel.apache.org/schema/spring"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:osgi="http://www.springframework.org/schema/osgi"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
       http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd">


    <bean id="Logger" class="com.logging.LoggerImpl" factory-method="getInstance"></bean>
    <osgi:service id="LoggerService" ref="Logger" interface="com.logging.Logger"></osgi:service>

  <camelContext autoStartup="true" xmlns="http://camel.apache.org/schema/spring"/>

</beans>

In this file i've created Spring bean of LoggerImpl Class and register it as OSGI service using SpringDM. Then i've created other Maven Project of ABC using servicemix-camel-osgi artifactId and in that project i've created one route file. it's looks like :

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:camel="http://camel.apache.org/schema/spring" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:osgi="http://www.springframework.org/schema/osgi"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
       http://www.springframework.org/schema/osgi  
       http://www.springframework.org/schema/osgi/spring-osgi.xsd">

    <import resource="classpath:spring-beans.xml" />

    <osgi:reference id="util_logger" interface="com.logging.Logger" bean-name="Logger"></osgi:reference>
    <camelContext trace="false" xmlns="http://camel.apache.org/schema/spring"/>

</bean>

so as shown in above file i've getting Logger service using OSGI Refrence.

Main motive for doing this is when i Register Logger OSGI service in Registry then any OSGI bundle can use that service using Reference of it rather than importing the package. Same thing want to implement in WSO2 but can't get any solution.

If any solution or suggestion then please suggest me, so i can achieve it. Thanks.

0

There are 0 answers