Source:
public Object intercept(MethodInvocationContext<Object, Object> context) { Optional<AnnotationValue<CircuitBreaker>> opt = context.findAnnotation(CircuitBreaker.class); if (!opt.isPresent()) { return context.proceed(); } ExecutableMethod executableMethod = context.getExecutableMethod(); final String name = executableMethod.stringValue(CircuitBreaker.class, "name").orElse("default"); io.github.resilience4j.circuitbreaker.CircuitBreaker circuitBreaker = this.circuitBreakerRegistry.circuitBreaker(name); ReturnType<Object> rt = context.getReturnType(); Class<Object> returnType = rt.getType(); if (CompletionStage.class.isAssignableFrom(returnType)) { return this.fallbackCompletable(circuitBreaker.executeCompletionStage(() -> ((CompletableFuture<?>) context.proceed())), context); } else if (Publishers.isConvertibleToPublisher(returnType)) { Object result = context.proceed(); if (result == null) { return result; } Flowable<Object> flowable = ConversionService.SHARED .convert(result, Flowable.class) .orElseThrow(() -> new UnhandledFallbackException("Unsupported Reactive type: " + result)); flowable = this.fallbackFlowable(flowable.compose(CircuitBreakerOperator.of(circuitBreaker)),context); return ConversionService.SHARED .convert(flowable, context.getReturnType().asArgument()) .orElseThrow(() -> new UnhandledFallbackException("Unsupported Reactive type: " + result)); } try { return circuitBreaker.executeCheckedSupplier(context::proceed); } catch (RuntimeException exception) { return fallback(context, exception); } catch (Throwable throwable) { throw new UnhandledFallbackException("Error invoking fallback for type [" + context.getTarget().getClass().getName() + "]: " + throwable.getMessage(), throwable); } }

Target:
public Object intercept(MethodInvocationContext<Object, Object> context) { Optional<AnnotationValue<CircuitBreaker>> opt = context.findAnnotation(CircuitBreaker.class); if (!opt.isPresent()) { return context.proceed(); } ExecutableMethod executableMethod = context.getExecutableMethod(); final String name = executableMethod.stringValue(CircuitBreaker.class, "name").orElse("default"); io.github.resilience4j.circuitbreaker.CircuitBreaker circuitBreaker = this.circuitBreakerRegistry.circuitBreaker(name); ReturnType<Object> rt = context.getReturnType(); Class<Object> returnType = rt.getType(); if (CompletionStage.class.isAssignableFrom(returnType)) { return this.fallbackCompletable(circuitBreaker.executeCompletionStage(() -> { try { return ((CompletableFuture<?>) context.proceed()); } catch (Throwable e) { throw new CompletionException(e); } }), context); } else if (Publishers.isConvertibleToPublisher(returnType)) { Object result = context.proceed(); if (result == null) { return result; } Flowable<Object> flowable = ConversionService.SHARED .convert(result, Flowable.class) .orElseThrow(() -> new UnhandledFallbackException("Unsupported Reactive type: " + result)); flowable = this.fallbackFlowable(flowable.compose(CircuitBreakerOperator.of(circuitBreaker)), context); return ConversionService.SHARED .convert(flowable, context.getReturnType().asArgument()) .orElseThrow(() -> new UnhandledFallbackException("Unsupported Reactive type: " + result)); } try { return circuitBreaker.executeCheckedSupplier(context::proceed); } catch (Throwable exception) { return fallback(context, exception); } }