Search code examples
javaasynchronousapache-camelintegrationrestlet

Restlet in Apache Camel without locking browser until completion


We are using Apache Camel integration platform and are updating some data through restlets. We want to know the status of this update as it takes several hours to complete. The problem we have is that we do not get a response from the program until the program has finished. Since the carrier type is of type restlet we have to wait until the job is finished because the browser is waiting for it to finish. We have looked into async ways to do it but it does not seem async is supported by restlet data carrier.

If we dont get any solution to this we have considered running the job using thread pool but we want to know if it is other methods to do jobs async because we might use the camel restlet more extensively later on and having jobs go async is preferable without executing threads every time.

Example code:

from("restlet:" +BASE_URL + "test1?restletMethods=get").
    routeId("Test 1").
    log(LoggingLevel.INFO, log.getName(), "Test 1 Started").
    delay(10000).
    log(LoggingLevel.INFO, log.getName(), "Test 1 Complete").
    to("mock:update");

As from the code above the browser waits 10 seconds before it responds. We want the browser to be immediately available, as well as getting data during this period.


Solution

  • Got it to work using SEDA with the option waitForTaskToComplete=Never in the "to" method.

    from("restlet:"+BASE_URL+"seda?restletMethods=get").
    routeId("SEDA async sender").
    log(LoggingLevel.INFO, log.getName(), "SEDA test started").
    log(LoggingLevel.INFO, log.getName(), "Transfer to SEDA...").
    to("seda:test1?waitForTaskToComplete=Never");
    
    from("seda:test1").
    threads(4).
    routeId("SEDA async receiver").
    log(LoggingLevel.INFO, log.getName(), "SEDA active").
    delay(4000).
    log(LoggingLevel.INFO, log.getName(), "SEDA test complete");
    //to("mock:update");