首页 文章

Apache Camel使用HTTP定义Route

提问于
浏览
1

如何使用HTTP为“from” endpoints 定义Camel Route?

我的目标是定义一个Route,当有HTTP请求时,Message将被排入ActiveMQ Queue .

我尝试了以下路径定义:

<route>
  <from uri="http://localhost:8181/cxf/crm/customerservice/customers" />
  <to uri="activemq:queue:LOG.ME" />
</route>

在浏览器中,我访问了以下URL:

http://localhost:8181/cxf/crm/customerservice/customers/123

我已经验证HTTP请求已到达Web服务“customerservice”,因为我收到了来自Web服务的XML响应 . 但是,ActiveMQ队列中没有列出任何消息 .

以下是处理来自ActiveMQ队列的消息的路径定义 .

<route>
  <from uri="activemq:queue:LOG.ME" />
  <multicast>
    <pipeline>
      <bean ref="processor1" method="handle" />
      <to uri="mock:result" />
    </pipeline>
    <pipeline>
      <bean ref="processor2" method="handle" />
      <to uri="mock:result" />
    </pipeline>
  </multicast>
</route>

我确认没有任何东西被排入ActiveMQ,因为我的bean“processor1”和“processor2”的“handle”方法没有被执行 .

如何使用HTTP为“from” endpoints 定义Camel Route?

谢谢 .

2 回答

  • 1

    如果要监听HTTP请求,则需要使用servlet组件(如果在Web应用程序中运行)或jetty组件嵌入简单的http服务器 .

    两者都有很好的文档和示例 .

    http和http4组件仅供 生产环境 者使用( <to ... /> ) .

  • 2

    要侦听传入的http请求,可以使用jetty或cxf组件设置代理,然后将调用Web服务以及将消息记录到activemq .

    例如,

    from("jetty:http://localhost:8282/xxx").
         to("http://localhost:8181/cxf/crm/customerservice/customers").
              to("activemq:queue:LOG.ME");
    

    现在,要访问Web服务,可以将代理调用为 http://localhost:8282/xxx ,而不是直接调用Web服务 . 也可以使用cxf组件设置代理,它有详细记录 .

相关问题