在Camel SpringBoot项目中传播请求参数值

时间:2019-03-25 07:56:23

标签: spring-boot apache-camel spring-camel

你好,我有Spring Boot 2项目,我正在用骆驼骑行。

我有一个骆驼休息终点和一条骆驼路线:

import UndoIcon from "!!raw-loader!quill/assets/icons/undo.svg"

我想做的是当我发送这样的请求时:

  

http://localhost:8080/camel/hello/?url=http://localhost:8081/hi

要在路由的第一个.to()中设置的url值:

  

.to(“ {url}?bridgeEndpoint = true”)

我也尝试过Spring Boot Rest Controller,但在.to($ {url}

 rest("/").produces("application/json")
.get("hello")
.param().name("url").type(RestParamType.query)
.dataType("String").endParam()
.to("direct:hello");
/////////////////////////////////////////////    
  System.out.println("starterd");
boolean startupRoute = true;
from("direct:hello").autoStartup(startupRoute)
    .tracing()
    .streamCaching()
    .process(exchange -> exchange.getIn()
        .setBody(exchange.getIn()
            .getBody()))
    .convertBodyTo(String.class)
    .marshal()
    .json(JsonLibrary.Jackson)
    .setHeader("Content-Type", constant("application/json"))
    .setHeader("Accept", constant("application/json"))
    .setHeader(Exchange.HTTP_METHOD, constant("GET"))
    .setHeader(Exchange.HTTP_URI).header("url")
    .log(LoggingLevel.INFO, "${body}")
    .removeHeader(Exchange.HTTP_PATH)
    .to("http4://url")
    .log(LoggingLevel.INFO, "This is my body: ${body}")
    .to("activemq://hello?exchangePattern=InOnly");
System.out.println("finished");

编辑:我已经编辑了路线

2 个答案:

答案 0 :(得分:3)

尝试一下

System.out.println("starterd");
boolean startupRoute = true;
from("direct:hello").autoStartup(startupRoute)
    .tracing()
    .streamCaching()
    .process(exchange -> exchange.getIn()
        .setBody(exchange.getIn()
            .getBody()))
    .convertBodyTo(String.class)
    .marshal()
    .json(JsonLibrary.Jackson)
    .setHeader("Content-Type", constant("application/json"))
    .setHeader("Accept", constant("application/json"))
    .setHeader(Exchange.HTTP_METHOD, constant("GET"))
    .setHeader(Exchange.HTTP_URI)
    .header("url")
    .log(LoggingLevel.INFO, "${body}")
    .removeHeader(Exchange.HTTP_PATH)
    .to("http4://url")
    .to("direct:hi");

from("direct:hi").log(LoggingLevel.INFO, "This is my body: ${body}")
    .recipientList(simple("activemq://${header.activemq}"+"?exchangePattern=InOnly"));
System.out.println("finished");

答案 1 :(得分:1)

您必须使用http组件http://camel.apache.org/http4.html

  

您可以通过在消息上添加带有密钥Exchange.HTTP_URI的标头来覆盖HTTP端点URI

.setHeader(Exchange.HTTP_URI).header("url")
.to("http4://dummy")