You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by Luis Alfredo Narvaez <lu...@gmail.com> on 2021/07/07 14:25:02 UTC

Outdated example on Camel Async page

Hello!

The examples on https://camel.apache.org/manual/latest/async.html , are
deprecated as they use an old version of AsyncProcessorHelper

Future<Exchange> future = AsyncProcessorHelper.asyncProcess(executor,
producer, exchange);

This API is no longer valid

Looking at Camel tests, I could find an example of AsyncProcessorHelper
usage on last version, on test CxfConsumerContinuationTimeoutTest here:
https://github.com/apache/camel/blob/camel-2.23.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerContinuationTimeoutTest.java

But I wonder if an example based on this code, like the following, is worth
showing for the page:

pool = getContext()
.getExecutorServiceManager()
.newSingleThreadExecutor(this, "MyPool");

...
.process(new AsyncProcessor() {
@Override
public void process(Exchange exchange) throws Exception
{
AsyncProcessorHelper.process(this, exchange);
}

@Override
public boolean process(Exchange exchange, AsyncCallback asyncCallback)
{
pool.submit(() -> {
try
{
String id = (String) exchange.getIn().getHeader("id");
LongRunningTask.execute();
String message = String.format("Ended long running proc for id: %s", id);
log.info("The result from long running process: " + message);
}
catch (InterruptedException ie) {
// ignore
}
catch (Exception e) {
e.printStackTrace();
}
finally
{
asyncCallback.done(false);
}
return false;
});
asyncCallback.done(false);
return false;
}
})


-- 
Atentamente,

Ing. Luis Alfredo Narváez Velez