Apache Camel用HTTP from定义路由



如何使用HTTP为"from"端点定义骆驼路由?

我的目标是定义一个路由,当有一个HTTP请求时,消息将在ActiveMQ队列上排队。

我尝试了以下路由定义:

<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 Queue上没有Message。

下面是处理来自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"one_answers"processor2"的"handle"方法没有执行。

如何定义骆驼路由与HTTP的"从"端点?

谢谢。

如果你想监听HTTP请求,那么你需要使用servlet组件(如果你在web应用程序中运行)或者使用嵌入简单HTTP服务器的jetty组件。

都有很好的文档和示例。

http和http4组件仅用于生产者(<to ... />)。

要监听传入的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组件来设置,文档中有详细说明。

最新更新