繁体   English   中英

将Apache Camel示例从Spring DSL转换为Java DSL

[英]Translating Apache Camel example from Spring DSL to Java DSL

我正在尝试将Spring DSL中的骆驼路线转换为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的示例中,我根本无法正确设置标头。 只是没有发生。 我知道这是因为行.setHeader(Exchange.HTTP_METHOD, constant("localhost:9991")) ,可能是Exchange.HTTP_METHOD部分,但是老实说,我不知道在那放什么。 我也尝试使用Exchange.HTTP_URI ,结果是相同的。

我的翻译有什么问题?

尝试这个

.exchange.getIn().setHeader("minaServer", constant("localhost:9991"))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM