我正在尝试将 Spring DSL 中的 Camel 路由转换为 Java DSL 中的等效路由。我完成了大部分翻译,但有件事我根本不知道该怎么做:更改标题。
以下是示例:
Spring DSL:
<bean id="service" class="org.apache.camel.example.service.Reporting" />
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route id="mina1">
<from uri="mina:tcp://localhost:9991" />
<setHeader headerName="minaServer">
<constant>localhost:9991</constant>
</setHeader>
<bean ref="service" method="updateReport" />
<to uri="direct:messageSender1" />
</route>
</camelContext>
Java DSL:
public void configure() throws Exception {
from("mina:tcp://localhost:9991")
.setHeader(Exchange.HTTP_METHOD, constant("localhost:9991"))
.beanRef("camel_examples.loadbalancer_failover_javadsl.service.Reporting", "updateReport")
.to("direct:messageSender1");
}
最后是使用 Header 的 bean 方法:
public Report updateReport(@Body Report report, @Header("minaServer") String name) {
report.setReply("Report passed by MINA servers running on: " + name);
return report;
}
现在,在使用 Spring DSL 的示例中,一切正常。但在使用 Java DSL 的示例中,我根本无法正确设置 header 。它只是不会发生。我知道其原因是行 .setHeader(Exchange.HTTP_METHOD,constant("localhost:9991"))
,可能是 Exchange.HTTP_METHOD
部分,但我知道说实话,也不知道该放什么。我还尝试了 Exchange.HTTP_URI
,结果是相同的。
我的翻译有什么问题吗?
最佳答案
试试这个
.exchange.getIn().setHeader("minaServer", constant("localhost:9991"))
关于java - 将 Apache Camel 示例从 Spring DSL 转换为 Java DSL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19824620/