【问题标题】:How to add osgi service reference in JAVA如何在JAVA中添加osgi服务引用
【发布时间】:2016-02-27 05:34:26
【问题描述】:

我是 fuse 的新手,正在开发组件测试。

我需要在 Java 中调用实现ActiveMQ(在fuse 之外)的组件。 在Spring 中会是这样的:

<osgi:reference id="activemq" interface="org.apache.camel.Component"
    filter="(component.name=ActiveMQ)"/>

但是我不知道如何在 Java 中引用这个组件。


终于找到了方法:

BundleContext ctx = FrameworkUtil.getBundle(YourClass.class).getBundleContext();

ServiceReference[] sRef;

sRef = ctx.getServiceReferences(Component.class.getName(), "(component.name={{YourComponentName}})");

Component amqComponent = (Component) ctx.getService(sRef[0]);

context.addComponent("activemq", amqComponent);

【问题讨论】:

  • 谢谢你 rkm_Hodor_king :)
  • @Marta Cruz,当您解决自己的问题时,您不得在问题中包含答案。相反,您必须将其添加为单独的答案

标签: java spring apache-camel activemq jbossfuse


【解决方案1】:

从外部,您需要使用 ActiveMQ 代理提供的任何传输连接器,通常是通过端口 61616 的 JMS,但它可以在代理端进行配置。然后它只是标准的 JMS / spring-jms / camel-jms 使用 ActiveMQ JMS 客户端并将其配置为在端口 61616 上使用 JMS(= 称为 openwire 协议)。

由于这不是 OSGi 的,因此互联网上有很多关于如何做到这一点的信息。或者查看一些 Camel 示例等。

【讨论】:

    猜你喜欢
    • 2013-06-14
    • 2010-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-06
    • 2013-08-26
    • 2015-10-14
    • 2015-01-04
    相关资源
    最近更新 更多