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?