繁体   English   中英

分布式OSGi-使用服务

[英]Distributed OSGi - Consuming the service

我必须编写一个可以远程访问的服务。 我正在使用cxf-dosgi-ri-singlebundle-distribution-1.4.0。 因此,我制作了具有以下属性的API,然后是实现:

Dictionary<String, String> restProps = new Hashtable<String, String>();

restProps.put("service.exported.interfaces", "*");
restProps.put("service.exported.configs", "org.apache.cxf.ws");
restProps.put("org.apache.cxf.ws.address", "http://192.168.0.3:9090/preview");
bundleContext.registerService(Preview.class.getName(), new PreviewService(),restProps);

如果部署捆绑软件,(在部署api和d-osgi jar之后),即使在远程计算机上,我也可以在浏览器中看到WSDL。 像这样的“ http://192.168.0.3:9090/preview?wsdl ”。

但是随后是消费者。 客户端jar中有OSGI-INF / remote-service / remote-services.xml,其中:

<endpoint-descriptions xmlns="http://www.osgi.org/xmlns/rsa/v1.0.0">
<endpoint-description>
<property name="objectClass">
    <array>
      <value>com.liferay.preview.api</value>
    </array>
</property>
<property name="endpoint.id">http://192.168.0.3:9090/preview</property>
<property name="service.imported.configs">org.apache.cxf.ws</property>
</endpoint-description>
</endpoint-descriptions>

我可以部署该捆绑包(在部署d-osgi捆绑包和API之后),但是我总是找回空引用。 本教程始终使用这样的代码

 st = new ServiceTracker(bundleContext, MyService.class.getName(), null) {
  @Override
  public Object addingService(ServiceReference reference) {
    Object svc = bundleContext.getService(reference);
    if (svc instanceof MyService) {
      printServiceInfo((MyService) svc);
    }

    return super.addingService(reference);
  } 
};
st.open();

但是我正在使用Liferay 7,在这里我不能使用它(没有ServiceTracker的构造函数-我只能从注册表实例中获取ServiceTracker实例)

OSGi容器是Felix。

我已经在某处阅读过它,如果我可以访问如上所示的WSDL描述,并且说,我的API中有一个hello()方法,然后是一个“ http://192.168.0.3:9090/preview/hello ”电话应该可以工作,但是不行。 我什至不知道如何调试它。 (没有远程的东西,在本地,在同一个容器中,方法调用起作用)

任何帮助都可以顺利进行! 谢谢!

一个更简单的解决方案是使用基于Zookeeper的发现。 捆绑请求此类服务后,服务器节点将发布它导出到Zookeeper的服务,而消费者节点将创建可立即使用的OSGi服务。

Riena Communication在发布和绑定远程服务方面不那么复杂。 它使用粗麻布作为通信协议。 与soap相比,它的确非常快,因为其基于二进制的协议(不是xml)

我希望这有帮助。

您应该使用基于Apache CXF的Liferay SOAP Extender。 您将找到Liferay开发人员网络的示例。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM