Search in sources :

Example 1 with RetryHandler

use of org.apache.servicecomb.governance.handler.RetryHandler in project java-chassis by ServiceComb.

the class InvokerUtils method decorateReactiveRetry.

private static void decorateReactiveRetry(Invocation invocation, DecorateCompletionStage<Response> dcs, GovernanceRequest request) {
    // governance implementations.
    RetryHandler retryHandler = BeanUtils.getBean(RetryHandler.class);
    Retry retry = retryHandler.getActuator(request);
    if (retry != null) {
        dcs.withRetry(retry, getOrCreateRetryPool());
    }
    if (isCompatibleRetryEnabled(invocation)) {
        // compatible implementation for retry in load balance module in old versions.
        retry = getOrCreateCompatibleRetry(invocation);
        dcs.withRetry(retry, getOrCreateRetryPool());
    }
}
Also used : RetryHandler(org.apache.servicecomb.governance.handler.RetryHandler) Retry(io.github.resilience4j.retry.Retry)

Example 2 with RetryHandler

use of org.apache.servicecomb.governance.handler.RetryHandler in project java-chassis by ServiceComb.

the class InvokerUtils method decorateSyncRetry.

private static Response decorateSyncRetry(Invocation invocation, GovernanceRequest request) {
    try {
        // governance implementations.
        RetryHandler retryHandler = BeanUtils.getBean(RetryHandler.class);
        Retry retry = retryHandler.getActuator(request);
        if (retry != null) {
            CheckedFunction0<Response> supplier = Retry.decorateCheckedSupplier(retry, () -> innerSyncInvokeImpl(invocation));
            return Try.of(supplier).get();
        }
        if (isCompatibleRetryEnabled(invocation)) {
            // compatible implementation for retry in load balance module in old versions.
            retry = getOrCreateCompatibleRetry(invocation);
            CheckedFunction0<Response> supplier = Retry.decorateCheckedSupplier(retry, () -> innerSyncInvokeImpl(invocation));
            return Try.of(supplier).get();
        }
        // retry not enabled
        return innerSyncInvokeImpl(invocation);
    } catch (Throwable e) {
        String message = String.format("invoke failed, operation %s, trace id %s", invocation.getMicroserviceQualifiedName(), invocation.getTraceId());
        LOGGER.error(message, e);
        Response response = Response.createConsumerFail(e, message);
        invocation.onFinish(response);
        return response;
    }
}
Also used : AsyncResponse(org.apache.servicecomb.swagger.invocation.AsyncResponse) Response(org.apache.servicecomb.swagger.invocation.Response) Exceptions.toConsumerResponse(org.apache.servicecomb.core.exception.Exceptions.toConsumerResponse) RetryHandler(org.apache.servicecomb.governance.handler.RetryHandler) Retry(io.github.resilience4j.retry.Retry)

Aggregations

Retry (io.github.resilience4j.retry.Retry)2 RetryHandler (org.apache.servicecomb.governance.handler.RetryHandler)2 Exceptions.toConsumerResponse (org.apache.servicecomb.core.exception.Exceptions.toConsumerResponse)1 AsyncResponse (org.apache.servicecomb.swagger.invocation.AsyncResponse)1 Response (org.apache.servicecomb.swagger.invocation.Response)1