Apache Camel BindException:"Can't Assign Requested Address"

Apache Camel BindException: "Can't Assign Requested Address"

我正在学习如何使用 Camel。我对以下代码片段有疑问:

@SpringBootApplication
public class FeefooExampleApplication {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(FeefooExampleApplication.class, args);

        CamelContext camelContext = new DefaultCamelContext();
        camelContext.addRoutes(new CamelConfig());
        camelContext.start();


        Blah blah = new Blah();

        blah.getFeefoData();

    }
}

我的 CamelConfig Class 如下:

package com.example.camel;


import com.example.feefo.FeedbackProcessor;
import org.apache.camel.builder.RouteBuilder;


public class CamelConfig extends RouteBuilder {


    private FeedbackProcessor feedbackProcessor = new FeedbackProcessor();

    @Override
    public void configure() throws Exception {
       from("jetty:http://cdn2.feefo.com/api/xmlfeedback?merchantidentifier=example-retail-merchant")
           .convertBodyTo(String.class)
           .bean(feedbackProcessor, "processFeedback")  ;

    }
}

报告的错误如下:“线程 "main" java.net.BindException 中出现异常:无法分配请求的地址”

有人能帮忙吗?

谢谢

当用作消费者时,jetty 组件会创建一个 HTTP 服务器,侦听 HTTP 请求,并使用该请求创建交换。

换句话说,当您执行 from("jetty:http://cdn2.feefo.com/..") 时,您要求码头创建一个 HTTP 服务器,其网络接口关联到 "cdn2.feefo.com":这失败了(好吧,我假设您的机器是不是这个主机)

如果你想请求这个HTTP地址,你必须使用jetty(或http4组件)作为生产者。例如:

from("direct:check_xmlfeedback")
  .to("jetty:http://cdn2.feefo.com/api/xmlfeedback?merchantidentifier=example-retail-merchant")
  ...

并调用您的路线:

context.getProducerTemplate().requestBody("direct:check_xmlfeedback", null);

如果要定期轮询此 HTTP 地址,可以使用 timer 组件:

from("timer:check?period=5m")
  .to("jetty:http://cdn2.feefo.com/api/xmlfeedback?merchantidentifier=example-retail-merchant")
  ...