【问题标题】:Loading a Service on startup of the ServiceMix 4.3 which consumes another service using ActiveMQ/Apache Camel在使用 ActiveMQ/Apache Camel 使用另一个服务的 ServiceMix 4.3 启动时加载服务
【发布时间】:2020-10-16 17:25:42
【问题描述】:

我们正在尝试在 SericeMix 启动期间在加载捆绑包后立即调用 ServiceA。 Service2 具有 activemq 端点,我们需要调用该特定服务的方法。我尝试了 bean 标记中的 spring init-method 属性,这有助于自动触发 ServiceA 中的方法,我正在调用 serviceB 的方法。我得到了端点没有可用的异常之类的异常。我假设只要 Service1 启动,它就不会获得需要使用 @Produce 注释 activemq 端点初始化的 service2 的实例。相同的服务在其他正常情况下也能正常工作。

例外: 原因:org.apache.camel.CamelExchangeException:端点上没有可用的消费者:端点 [direct://ServiceB]。 Exchange[消息:BeanInvocation public java.lang.String java.lang.Object.toString() with null]] 在 org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:46) 在 org.apache.camel.component.bean.CamelInvocationHandler.invoke(CamelInvocationHandler.java:64) ... 35 更多

我复制粘贴代码块供您参考。

public class ServiceA{

    @Produce(uri = "direct:ServiceB") //Active MQ endpoint
    private ServiceB serviceB;

     public void start()
    {
        Object obj = serviceB.getData();    }
        . . . 
        .....   
    }
  }

     **bundle-context.xml**

        //Changes for method to auto trigger during spring bean load
        <bean id="serviceA" class="com.test.serviceA" init-method="start">
        </bean>

      **bundle-context-camel.xml**

         <osgi:camelContext id="ServiceA"
    xmlns="http://camel.apache.org/schema/spring">
    <template id="producerTemplate" />

    <!-- These routes are outbound to other services -->
    <route>
        <from uri="ServiceB" />
        <bean ref="enrichOutboundExchangeRef" />
        <to uri="activemq:ServiceB?transferException=true" />
    </route>
               ..............
    </osgi:camelContext>

如果我需要达到这个要求,他们还有其他方式吗?我可以在 servicemix 启动期间自动加载服务(使用其他服务)。

【问题讨论】:

  • 令人困惑的帖子...ServiceA/B vs Service1/2??另外,您有一个标有“ActiveMQ 端点”的“direct:ServiceB”端点……不确定您要做什么。清理问题,我们可能会提供帮助......

标签: apache-camel apache-servicemix fuseesb


【解决方案1】:

您可以使用 seda 而不是直接,因为它是基于队列的,因此消费者可以来来去去。

也可以尝试使用 springs 依赖属性

<bean id="serviceA" depends-on="myCamel" .../>

<osgi:camelContext id="myCamel" ...>

【讨论】:

    【解决方案2】:

    我们尝试了上述方法,但仍然遇到异常,我们通过在 serviceA 的初始化期间向 onCamelContextStarted() 添加一个侦听器来解决它。

    谢谢 拉维

    【讨论】:

      【解决方案3】:

      如果您得到“端点上没有可用的消费者”,这意味着消息正在被路由到尚未初始化的端点。我建议使用它们之间的 JMS 队列来解耦这些服务。这样,serviceA 可以将消息放入队列中(独立于 serviceB 的可用性),然后 serviceB 可以在该队列准备就绪时充当该队列的轮询消费者。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-10-16
        • 2014-09-02
        • 1970-01-01
        • 2015-09-04
        • 2012-08-16
        • 2021-12-09
        • 1970-01-01
        • 2020-09-07
        相关资源
        最近更新 更多