Suraj
Suraj

Reputation: 3

Asynchronous routing and parameter passing

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...
    }
});

I need Point X to be asynchronous. I want the requestId as shown in Point X to be avaliable in Y and Z. This is because, logging to a database takes time and I want it to be asynchronous so that it won't affect performance. Please help me.

Upvotes: 0

Views: 201

Answers (1)

Claus Ibsen
Claus Ibsen

Reputation: 55540

I assume logRequestToDatabase is a method, and therefore you can implement the code in that method to run async, so the Camel process method can continue. If point Y and Z need access to the result of the logRequestToDatabase invocation, you can use a JDK Future for that.

Upvotes: 1

Related Questions