Skip to content

Concurrent execution, Dispatch Compose

Regunath B edited this page Aug 21, 2018 · 9 revisions

Concurrent Execution

Concurrent execution is enabled by wrapping methods annotated like @ConcurrentTask(timeout = 300) as HystrixCommand. This would execute the method asynchronously and provide properties of a HystrixCommand.

All currently executing async methods can be visualized using the Hystrix dashboard available in GJEX as : http://hostname:9999/admin/dashboard like below:

Dispatch-Compose

Methods annotated with @ConcurrentTask(...) can further be composed in a Dispatch-Compose manner using a FutureDecorator API. Methods would additionally require method signature like below:

@ConcurrentTask(timeout = 300)
public Future<T> foo(V v) {
    return new AsyncResult<T>() {
        @Override
        public T invoke() {
        .......implement method....
        }
    }
}

Subsequently, these methods may be dispatched and composed using one of the FutureDecorator#compose() methods like:

FutureDecorator<T> future1 = (FutureDecorator<T1>)this.foo1();
FutureDecorator<T> future2 = (FutureDecorator<T2>)this.foo2();
S response = FutureDecorator.compose(future1, future2, new BiFunction<T1,T2>(){
    public S apply(T1 t1, T2 t2) {
    ... compose result from execution results T1, T2
    }
}

Composing Optional and Mandatory Concurrent tasks

@ConcurrentTask(...) annotations may additionally be marked with a 'Completion' attribute like completion=ConcurrentTask.Completion.Optional to indicate that a null result due to error or timeout in task execution is acceptable and the execution may proceed. The result offered to the BiFunction#apply() callback is null in such cases.

See Full example source for complete example and the corresponding trace across the entire call-graph is like below: