注册OSGI服务并使用WSO2产品获取该OSGI服务参考

时间:2013-08-30 10:41:15

标签: osgi wso2 wso2esb spring-dm

实际上我想将我的应用程序从FUSE ESB迁移到WSO2esb。 在我的FUSE应用程序中,我为Logger创建了一个OSGI包,并在OSGI注册表中注册了Logger服务。其他OSGI包可以通过引用获得该OSGI服务。

我使用servicemix-camel-osgi artifactId为Logger创建了一个OSGI maven项目。 我使用Apache Camel Approach,因此创建了一个MainRoute xml文件。

<?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>

在这个文件中,我创建了LoggerImpl类的Spring bean,并使用SpringDM将其注册为OSGI服务。 然后我使用servicemix-camel-osgi artifactId创建了ABC的其他Maven项目,在该项目中我创建了一个路径文件。 它看起来像:

<?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>

所以如上面的文件所示,我使用OSGI Refrence获得了Logger服务。

这样做的主要动机是当我在注册表中注册Logger OSGI服务时,任何OSGI包都可以使用该服务使用该服务,而不是导入包。 同样的事情想在WSO2中实现,但无法得到任何解决方案。

如果有任何解决方案或建议请建议我,所以我可以实现它。 感谢。

0 个答案:

没有答案