在 ServiceMix 4.3 启动时加载服务,该服务使用 ActiveMQ/Apache Camel 消耗另一个服务
我们正在尝试在 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 技术交流群。
发布评论
评论(3)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
您可以使用 seda 而不是 direct,因为它是基于队列的,因此消费者可以来来去去。
还可以尝试使用 springs dependent-on 属性
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