在 ServiceMix 4.3 启动时加载服务,该服务使用 ActiveMQ/Apache Camel 消耗另一个服务

发布于 10-07 17:04 字数 1782 浏览 8 评论 0原文

我们正在尝试在 SericeMix 启动期间一旦捆绑包加载,ServiceA 就调用 ServiceB。 Service2 具有 activemq 端点,我们需要调用该特定服务的方法。我尝试通过 bean 标记中的 spring init-method 属性来帮助自动触发 ServiceA 中的方法,在该方法中我调用 serviceB 的方法。我收到异常,例如端点没有可用的消费者。我假设 Service1 启动后,它就无法获取需要使用 @Produce 注释 activemq 端点进行初始化的 service2 的实例。相同的服务在其他正常场景下工作正常。

例外: 引起原因:org.apache.camel.CamelExchangeException:端点上没有可用的消费者:Endpoint[direct://ServiceB]。交换[消息:BeanInspiration 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.CamelInvocalHandler.invoke(CamelInvocalHandler.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 启动期间自动加载服务(使用其他服务)。

We are trying with ServiceA calling ServiceB as soon as bundle loads during the SericeMix startup. Service2 having activemq endpoints we need to invoke a method of that particular service. I tried by spring init-method attribute in the bean tag which helps in auto trigger a method in ServiceA in that method I am calling the serviceB’s method. I am getting Exception like No Consumer available for the endpoint. I assume that as soon as the Service1 is up it is not getting the instance of the service2 which needs to get initialized using @Produce annotation activemq endpoint. The same services work fine in the other normal scenarios.

Exception:
Caused by: org.apache.camel.CamelExchangeException: No consumers available on endpoint: Endpoint[direct://ServiceB]. Exchange[Message: BeanInvocation public java.lang.String java.lang.Object.toString() with null]]
at org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:46)
at org.apache.camel.component.bean.CamelInvocationHandler.invoke(CamelInvocationHandler.java:64)
... 35 more

I am copy pasting the Code Block for your reference.

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>

Or is their anyother way if i need to achieve this requirement? where i can load a service(consumes other services) automatically during the servicemix bootup.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

空心空情空意2024-10-14 17:04:55

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

还可以尝试使用 springs dependent-on 属性

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

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

You can use seda instead of direct as it's queue based and thus consumers can come and go.

Also try using springs depends-on attribute

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

<osgi:camelContext id="myCamel" ...>
笛声青案梦长安2024-10-14 17:04:55

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

谢谢
拉维

We tried the above approach but we still we are getting exceptions, we resolved it by adding a listener to the onCamelContextStarted() during th init of the serviceA.

Thanks
Ravi

暮光沉寂2024-10-14 17:04:55

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

If you are getting "no consumers available on endpoint", it means that messages are being routed to an endpoint that hasn't been initialized. I recommend decoupling the services using a JMS queue between them. That way serviceA can put messages in the queue (independent of serviceB's availability) and serviceB can then act as a polling consumer against that queue whenever its ready.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文