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

标签 java spring apache-camel

我正在尝试将 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/

相关文章:

java - Spring 5 和 Kotlin 1.1 协程 : Type rx. 调度程序不存在

java - ProjectForge 中的 LifecycleException

java - 将值传递给方法 onSuccess

java - 如何在 Netbeans 平台中启用/禁用操作

java - Spark flatMap/减少 : How to scale and avoid OutOfMemory?

java - Camel 休息路线在异常时不返回状态码

spring - 如何从同一端口上的spring boot应用程序启动wiremock服务器?

java - Spring 安全性和自定义 AuthenticationFilter 与 Spring boot

elasticsearch - 数据已使用 Camel 索引到 Elasticsearch 中,但无法在Kibana或localhost:9200中看到

java - 如何使用camel删除超过几天的文件夹