有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java异步路由和参数传递

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中可用。这是因为,记录到数据库需要时间,我希望它是异步的,这样就不会影响性能。 请帮帮我


共 (1) 个答案

  1. # 1 楼答案

    我假设logRequestToDatabase是一个方法,因此您可以在该方法中实现代码以运行异步,这样驼峰进程方法就可以继续。如果点Y和点Z需要访问logRequestToDatabase调用的结果,那么可以使用JDK Future进行访问