0
from(routeA)
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
//Point X
int requestId = logRequestToDatabase(exchange.getIn().getBody(String.class));
// need to use this requestId at point Y and Z..
}
})
.wireTap(routeT)
.to(routeB)
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
//Point Y
// i need the requestId from X here to mark it to log the response to database...
}
});
from(routeT)
.to(routeC)
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
//Point Z
// i need the requestId from X here to mark it to log the response to database...
}
});
我需要X点是异步的。我希望点X中的requestId
在Y和Z中可用。这是因为记录到数据库需要时间,我希望它是异步的,因此它不会影响性能。 请帮帮我。异步路由和参数传递
你能告诉我我如何获得值@X到Y n Z?我不能使用全局变量,因为它们倾向于与每个请求重叠。我的意思是,如果在前一个到达点Y n Z之前有新的请求,旧值将被覆盖。 – Suraj
您可以在Exchange属性中存储信息。它们是交易所本地的,最后是它的生命周期。因此,例如,当logRequestToDatabase完成时,它可以将结果作为属性存储在交换机上。你可以从Y和Z访问。你可能需要等到Y和Z直到结果准备好。为此,可以使用JDK Future抽象。或者其他一些手段。 –
由于您使用wireTap创建了一个新的Exchange。因此,您需要先将一些持有者对象存储到交换中,以便持有者对象被复制,以便您可以使用它访问X和Y处的值。此类持有者可能是JDK Future。 –