【问题标题】:Camel Rest DSL - multicast and early reply to http clientCamel Rest DSL - 多播和提前回复 http 客户端
【发布时间】:2017-01-11 21:55:45
【问题描述】:

骆驼版本是2.18.1

我有以下路线:

1:rest dsl 接受来自 HTTP 客户端的数据并将其发送到路由 在回复客户之前在下面。

rest("/api")
    .post("/commands/{command}").to("direct:commands")

2:将命令路由到两个端点longRunningProcesshortRunningProcessWhichMustSendRespondToHttpClient 的多播。

from("direct:commands")
    .multicast()
        .to("direct:longRunningProces")
        .to("direct:shortRunningProcessWhichMustSendRespondToHttpClient");

如何将来自 shortRunningProcessWhichMustSendRespondToHttpClient 路由的响应发送到 Http 客户端?

【问题讨论】:

    标签: rest apache-camel


    【解决方案1】:

    因为你使用多播主线程正在等待响应。

    使用wireTap

    http://camel.apache.org/wire-tap.html

    路线看起来像这样

    from("direct:commands")
    .wireTap("direct:longRunningProces") //<<- seperate thread to process this route
        .to("direct:shortRunningProcessWhichMustSendRespondToHttpClient");
    

    这是完整的代码 github

    【讨论】:

    • 感谢您的帮助
    • 除此之外,应该使用设计透视窃听来截取组件之间的消息以用于分析/调试目的。 (例如:您可以将有效负载发送到不同的流以登录数据库以进行审计)。如果您想在单独的线程中执行长时间运行的进程 - 异步方式,只需将您的直接替换为“SEDA”
    • @GnanaGuru 你是这个意思吗? from("direct:commands") .multicast() .to("seda:longRunningProces") .to("direct:shortRunningProcessWhichMustSendRespondToHttpClient");
    • 是的,你可以使用你提到的。如果您不想进行多播,可以这样使用,from("direct:commands") .to("seda:longRunningProces") .to("direct:shortRunningProcessWhichMustSendRespondToHttpCli‌​ent"); 注意:多播会将相同的消息投射到多个端点;默认情况下是异步的。在我的示例中,单独的 seda 表现为异步方式。
    • @GnanaGuru 它不起作用...客户端仍在等待长时间运行进程的响应
    猜你喜欢
    • 2018-10-01
    • 2019-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多