[英]Apache camel 2.16 enrich - No consumers available on endpoint in JUnit
I upgraded to camel 2.16 and one of my route Unit Tests started failing. 我升级到骆驼2.16,并且我的一项路线单元测试开始失败。
Here is my route definition: 这是我的路线定义:
public class Route extends RouteBuilder{
@Override
public void configure() throws Exception {
from(start).enrich("second");
from("direct:second")
.log(LoggingLevel.DEBUG, "foo", "Route [direct:second] started.");
}
}
Here is my test: 这是我的测试:
@RunWith(MockitoJUnitRunner.class)
public class RouteTest extends CamelTestSupport {
private Route builder;
@Produce(uri = "direct:start")
protected ProducerTemplate template;
@Before
public void config() {
BasicConfigurator.configure();
}
@Override
protected RouteBuilder createRouteBuilder() {
builder = new Route();
return builder;
}
@Override
protected CamelContext createCamelContext() throws Exception {
SimpleRegistry registry = new SimpleRegistry();
return new DefaultCamelContext(registry);
}
@Test
public void testPrimeRouteForSubscriptionId() {
Exchange exchange = ExchangeBuilder.anExchange(new DefaultCamelContext()).build();
exchange.getIn().setBody(new String("test"));
template.send(exchange);
}
}
The error I'm getting when I run the test is: 运行测试时出现的错误是:
org.apache.camel.component.direct.DirectConsumerNotAvailableException: No consumers available on endpoint: Endpoint[direct://second]. Exchange[][Message: test]
Worthy of note is the following line in the camel 2.16 notes: http://camel.apache.org/camel-2160-release.html 值得注意的是骆驼2.16注释中的以下行: http : //camel.apache.org/camel-2160-release.html
The resourceUri and resourceRef attributes on and has been removed as they now support a dynamic uris computed from an Expression. 和上的resourceUri和resourceRef属性已被删除,因为它们现在支持根据表达式计算的动态uri。
Thanks in advance for any help. 在此先感谢您的帮助。
Swap the order so the the direct route is started before the enrich. 交换订单,以便在浓缩之前开始直接路线。 http://camel.apache.org/configuring-route-startup-ordering-and-autostartup.html
http://camel.apache.org/configuring-route-startup-ordering-and-autostartup.html
Or use seda instead of direct in your unit test: http://camel.apache.org/seda 或在您的单元测试中使用seda代替直接使用: http : //camel.apache.org/seda
Or use ?block=true
in the direct uri to tell Camel to block and wait for a consumer to be started and ready before it sends a message to it: http://camel.apache.org/direct 或者在直接uri中使用
?block=true
来告诉Camel阻止并等待消费者启动并准备就绪,然后再向其发送消息: http : //camel.apache.org/direct
The blueprint test keeps throwing exception, No Consumers available. 蓝图测试不断抛出异常,没有可用的使用者。
My scenario was that I have an osgi svc which exposes a method which can be called from any another osgi svc . 我的情况是我有一个osgi svc ,它公开了可以从任何其他osgi svc调用的方法。
So the exposed svc method makes a call to a direct: 因此,公开的svc方法调用了直接方法:
@EndpointInject(uri = "direct-vm:toRestCall")
ProducerTemplate toRestCall;
svcMethod(Exchange xch){
exchange.setOut(
toRestCall.send("seda:toDirectCall", xch -> {
try{
xch.getIn().setBody("abc");
}catch (Exception ex){
ex.getMessage();
}
}
}).getIn());
And when I tested the direct that it calls, Blueprint advice with JUnit
used to keep throwing the following exception: 当我测试它所调用的直接指令时,带有
JUnit
Blueprint建议常会JUnit
以下异常:
org.apache.camel.component.direct.DirectConsumerNotAvailableException: No consumers available on endpoint: Endpoint.
org.apache.camel.component.direct.DirectConsumerNotAvailableException:在终结点:端点上没有可用的使用者。 Exchange[Message: {..........
Exchange [消息:{..........
This is a somewhat old issue, but since i pulled out most of my hair out last night, trying to figure out why it was ok to use to("direct:myEndpoint")
but not enrich("direct:myEndpoint")
, I'll post the answer anyway - maybe it'll save somebody else from getting bald spots ;-) 这是一个有点老的问题,但是由于我昨晚抽出了大部分头发,试图弄清楚为什么可以使用
to("direct:myEndpoint")
而不是enrich("direct:myEndpoint")
,所以我无论如何都会发布答案-也许它将使其他人免于秃头;-)
It turns out to be a test-issue. 事实证明这是一个测试问题。 In case of Direct endpoints, enrich checks whether there is a running route in the context before passing the Exchange to it, but it does so by looking at the CamelContext held by the Exchange it is currently handling.
如果是Direct终结点,则rich将在将Exchange传递给上下文之前检查上下文中是否存在正在运行的路由,但这是通过查看当前正在处理的Exchange所拥有的CamelContext来进行的。 Since you passed your ProducerTemplate an Exchange what was created with a
new DefaultCamelContext()
, it has no "direct:second" route available. 自从您的ProducerTemplate通过Exchange传递之后,使用
new DefaultCamelContext()
创建的对象就没有可用的“ direct:second”路由。
Luckily there is a couple of simple solutions. 幸运的是,有两个简单的解决方案。 Either create the Exchange using the CamelContext from CamelTestSupport, or use the ProducerTemplate
sendBody(...)
method instead: 使用来自CamelTestSupport的CamelContext创建Exchange,或者改为使用ProducerTemplate
sendBody(...)
方法:
@Test
public void testWithSendBody() {
template.sendBody(new String("test"));
}
@Test
public void testPrimeRouteForSubscriptionId() {
Exchange exchange = ExchangeBuilder.anExchange(context()).build();
exchange.getIn().setBody(new String("test"));
template.send(exchange);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.