我有两个查询:
1.我们可以在骆驼中使用非阻塞的异步路由吗?我确实看到与seda
异步,但是如果将工作卸载到其他阻塞的线程。
2.如果可以,我们可以在此类路由中使用多播。
以下是我的多步骆驼路线,该路线似乎有效。但不确定是异步还是非阻塞异步。
from("direct:multiStep")
.to("bean:routeHandler?method=monoReturningMethod1")
.process(new UnwrapStreamProcessor())
.to("bean:routeHandler?method=monoReturningMethod2")
.process(new UnwrapStreamProcessor())
以上工作正常,并且Web请求收到了monoReturningMethod
的响应。在这种情况下,我要确保所有进程都不会阻塞。
对于多播,我正在尝试以下路由。不确定将UnwrapStreamProcessor
放在哪里。我尝试将其放在end()
之后,但是不起作用。我需要自定义的Processor
吗?或者如何将所有Mono
的退货捆绑在一起?
from("direct:incoming")
.multicast()
.parallelProcessing()
.to("bean:routeHandler?method=monoReturningMethod1","bean:routeHandler?method=monoReturningMethod2")
.end()
我正在使用带有弹簧启动启动器的apache`camel 3.0.1。
@Component("routeHandler")
public class RouteHandler {
Mono<Entity> monoReturningMethod1(Exchange exchange) {
//make some WebClient request which returns Mono.
}
Mono<Entity> monoReturningMethod2(Exchange exchange) {
//make some WebClient request which returns Mono.
}
}
此路由处理传入的Web请求。如何使所有路由处理无阻塞和异步。我尝试在process(new UnwrapStreamProcessor())
之后使用monoReturningMehtod
作为处理步骤,如果我按顺序进行,它可以工作。但是它不适用于多播,并且不允许覆盖原始消息。
有什么建议吗?
PS:我正在启动异步流程,如下所示:
producerTemplate.asyncSend("RouteName",exchange)