2017-05-04 63 views
0

我創建了一個端點`直接駱駝路線駱駝路線終點:getRestFromExternalService,當我嘗試在主要的方法來使用這個端點另一個類中我得到一個異常調用主類

交換[ID-WMLI118067-61025-1493883025815-0-2]

沒有消費者對端點可用:在交易所執行過程中發生的異常端點[直接: // getRestFromExternalService。交換[ID-WMLI118067-61025-1493883025815-0-2]

這是路由類:

public class MyRoute extends RouteBuilder { 

@Override 
public void configure() throws Exception { 

    // Create the camel context for the REST API routing in Fuse 
      CamelContext contextFuseAPI = new DefaultCamelContext(); 

      // Start the route inside the context to listen to the ActiveMQ 
      contextFuseAPI.addRoutes(new RouteBuilder() { 

       @Override 
       public void configure() { 
        from("direct:getRestFromExternalService") 
         .setHeader(Exchange.HTTP_METHOD, simple("GET")) 
         .to("<external API URI>"); 
       } 
}); 
} 
} 

這是與調用該路由main方法的類:

public class FuseApp { 

public static void main(String[] args) throws Exception { 
    CamelContext contextFuseAPI = new DefaultCamelContext(); 

    contextFuseAPI.addRoutes(new MyRoute()); 

    contextFuseAPI.start(); 

    Thread.sleep(3000); 

    ProducerTemplate template = contextFuseAPI.createProducerTemplate(); 

    Object result = template.requestBody("direct:getRestFromExternalService", null, String.class); 


    Exchange exchange = new DefaultExchange(contextFuseAPI); 
    String response = ExchangeHelper.convertToType(exchange, String.class, result); 
    System.out.println("Response : "+ response);   

    contextFuseAPI.stop(); 


} 

} 

我測試了沒有ProducerTemplate和Object行的主要方法,它運行。有沒有辦法使用不同類中實現的路由與端點調用requestBody?

回答

0

我解決了這個問題,問題是在路由類和main方法類中都創建了上下文。