2016-06-28 49 views
1

我升級到駝峯2.16,我的一個路由單元測試開始失敗。阿帕奇駱駝2.16補充 - 沒有消費者可用在JUnit端點

這裏是我的路由定義:

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."); 

    } 
} 

這裏是我的測試:

@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); 
    } 
} 

當我運行測試,我得到的錯誤是:

org.apache.camel.component.direct.DirectConsumerNotAvailableException: No consumers available on endpoint: Endpoint[direct://second]. Exchange[][Message: test] 

沃西值得注意的是駱駝下面的一行2.16備註: http://camel.apache.org/camel-2160-release.html

resourceUri和resourceRef屬性已被刪除,因爲它們現在支持從表達式計算出的動態uris。

在此先感謝您的幫助。

回答

3

交換訂單,以便在豐富之前啓動直接路由。 http://camel.apache.org/configuring-route-startup-ordering-and-autostartup.html

或者使用SEDA,而不是直接在單元測試:http://camel.apache.org/seda

或者使用?block=true在直接URI來告訴駱駝阻止,等待消費者開始並準備將消息發送給前它:http://camel.apache.org/direct

+0

嗨克勞斯,感謝您的建議。他們沒有解決這個問題,但我看到了相同的錯誤信息。 現在我已經選擇重寫我的路線,避免豐富,但知道如何使豐富的工作是很好的。 再次感謝。 –

0

藍圖測試一直拋出異常,沒有消費者可用。

我的情況是,我有一個OSGi的SVC它公開了一個可以從任何其他OSGi的SVC調用的方法。

因此暴露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()); 

當我測試了一下它調用直接與JUnit藍圖建議用來保持拋出以下異常:

org.apache.camel.component.direct.DirectConsumerNotAvailableException: 端點上沒有可用的客戶端:端點。交換[消息:{..........

+0

請不要添加「謝謝」作爲答案。相反,投票答案,你覺得有幫助。 - [來自評論](/ review/low-quality-posts/17466394) – kaliatech