【问题标题】:Camel RabbitMQ Request Response Pattern ExampleCamel RabbitMQ 请求响应模式示例
【发布时间】:2015-02-25 09:51:02
【问题描述】:

我正在寻找使用 Camel RabbitMQ 请求响应模式的示例代码。

我的用例: - 请求消息存放在 RabbitMQ 队列中 - Camel 路由消费消息,调用外部 Web 服务,并根据消息的回复属性回复响应

我也使用 Spring AMQP 实现了这个用例,但我也想用 Camel RabbitMQ 来实现。

骆驼文档:http://camel.apache.org/rabbitmq.html

感谢您的帮助。

阿诺

【问题讨论】:

    标签: design-patterns request apache-camel rabbitmq response


    【解决方案1】:

    我找到了解决方案:

    Camel RabbitMQ 回复功能将在下一个 Camel 版本 2.15 中提供。

    参照。 https://issues.apache.org/jira/browse/CAMEL-7860

    阿诺

    【讨论】:

      【解决方案2】:

      这是一个简单的 HTTP 代理示例。 HTTP 请求通过 Rabbit MQ,然后 HTTP 响应返回到 Rabbit MQ。

      camel 2.17.1 上编写的示例(camel-core、camel-netty4-http、camel-rabbitmq)

      示例调用:

      curl -H "proxy_url:http://remotehost:port/uri" 127.0.0.1

          context.addRoutes(new RouteBuilder() {
      
              @Override
              public void configure() throws Exception {
      
                  from("netty4-http:localhost:80").
                          to("rabbitmq://localhost:5672/async");
      
                  from("rabbitmq://localhost:5672/async").
                          process(exchange -> {
      
                              // for return not only 200 HTTP STATUS
                              String techParams = "throwExceptionOnFailure=false";
                              String proxyUrl = (String) exchange.getIn().getHeader("proxy_url");
      
                              proxyUrl = proxyUrl.contains("?") && proxyUrl.contains("=") 
                                      ? proxyUrl + "&" + techParams : proxyUrl + "?" + techParams;
                              exchange.getIn().setHeader("proxy_url", proxyUrl);
      
                              exchange.setProperty(RabbitMQConstants.CORRELATIONID, 
                                      exchange.getIn().getHeader(RabbitMQConstants.CORRELATIONID));
      
                          }).
                          toD("netty4-http:${header.proxy_url}").
                          process(exchange -> {
                              exchange.getIn().setHeader(RabbitMQConstants.CORRELATIONID, exchange.getProperty(RabbitMQConstants.CORRELATIONID));
                          });
              }
      
          });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-10-07
        • 1970-01-01
        • 1970-01-01
        • 2012-08-11
        • 2020-03-24
        相关资源
        最近更新 更多