【发布时间】:2017-05-04 07:47:13
【问题描述】:
我创建了一个带有端点 `direct:getRestFromExternalService 的 Camel 路由,当我尝试在另一个类中的 main 方法中使用此端点时,我得到一个异常
在交易所执行期间发生异常:Exchange[ID-WMLI118067-61025-1493883025815-0-2]
和
端点上没有可用的消费者:Endpoint[direct://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>");
}
});
}
}
这是具有调用此路由的主要方法的类:
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 行的情况下测试了 main 方法,它运行了。有没有办法通过在不同类中实现的路由的端点调用 requestBody?
【问题讨论】:
标签: java apache-camel