gpt4 book ai didi

apache-camel - 如何使用异步子路由连接 Apache Camel 同步请求/回复端点

转载 作者:行者123 更新时间:2023-12-01 04:04:40 25 4
gpt4 key购买 nike

我想将 web 服务请求路由到 jms 队列的 InOnly 端点。然后将从单独的 InOnly 端点接收到的响应 jms 消息路由回 Web 服务客户端作为响应。 webservice请求/响应是同步InOut模式,子路由是异步的。我有什么选择可以用 Camel 实现这一目标?

这里的 Camel 路线用于解释我的问题:

String uri={webserice uri}
from(uri)
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
ServcieRequest req =
exchange.getIn().getBody(ServcieRequest.class);
// One option to me is to spawn another route here to route to jms queue...
ProducerTemplate template = exchange.getContext().createProducerTemplate();
template.sendBodyAndHeaders("jms:queue:INQueue", req.getPayload(), headers);
// then need to wait ...until received jms response from the route below

}});


from("jms:queue:OUTQueue")
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
// received jms response message
// need to update the exchange data in the above route based on jms message
// so the final response to the webservice cilent can receive the data ...
}});

最佳答案

我认为您应该依靠 Camel 中的请求回复机制来完成此任务。
Camel Doc, Exclusive Fixed Reply Queue

所以我猜下面的 DSL 路由几乎可以满足您的需求(如果没有其他原因为什么您应该对 JMS 部分使用 InOnly 模式?)。如果需要,请确保调整 requestTimeout(因为它默认为 20 秒超时)。

from(webserviceURI)
.inOut().to("jms:queue:INQueue?replyTo=OUTQueue?replyToType=Exclusive");

是的,还有一件事。如果您在多个节点上运行它,那么每个节点需要一个独占队列。

关于apache-camel - 如何使用异步子路由连接 Apache Camel 同步请求/回复端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10253656/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com