com.alibaba.csp.sentinel.adapter.dubbo.fallback.DubboFallbackRegistry Java Examples

The following examples show how to use com.alibaba.csp.sentinel.adapter.dubbo.fallback.DubboFallbackRegistry. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FooConsumerBootstrap.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 5 votes vote down vote up
private static void registerFallback() {
    // Register fallback handler for consumer.
    // If you only want to handle degrading, you need to
    // check the type of BlockException.
    DubboFallbackRegistry.setConsumerFallback((a, b, ex) ->
        new RpcResult("Error: " + ex.getClass().getTypeName()));
}
 
Example #2
Source File: FooConsumerBootstrap.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
private static void registerFallback() {
    // Register fallback handler for consumer.
    // If you only want to handle degrading, you need to
    // check the type of BlockException.
    DubboFallbackRegistry.setConsumerFallback((a, b, ex) ->
        new RpcResult("Error: " + ex.getClass().getTypeName()));
}
 
Example #3
Source File: SentinelDubboConsumerFilterTest.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
private void initFallback() {
    DubboFallbackRegistry.setConsumerFallback(new DubboFallback() {
        @Override
        public Result handle(Invoker<?> invoker, Invocation invocation, BlockException ex) {
            boolean async = RpcUtils.isAsync(invoker.getUrl(), invocation);
            Result fallbackResult = null;
            fallbackResult = AsyncRpcResult.newDefaultAsyncResult("fallback", invocation);
            return fallbackResult;
        }
    });
}
 
Example #4
Source File: BaseTest.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
private void clearDubboContext() {
    SentinelConfig.setConfig("csp.sentinel.dubbo.resource.use.prefix", "false");
    SentinelConfig.setConfig(DubboConfig.DUBBO_PROVIDER_PREFIX, "");
    SentinelConfig.setConfig(DubboConfig.DUBBO_CONSUMER_PREFIX, "");
    SentinelConfig.setConfig(DubboConfig.DUBBO_INTERFACE_GROUP_VERSION_ENABLED, "false");
    DubboFallbackRegistry.setConsumerFallback(new DefaultDubboFallback());
    RpcContext.removeContext();

}
 
Example #5
Source File: FooConsumerBootstrap.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
public static void registryCustomFallback() {
    DubboFallbackRegistry.setConsumerFallback(
            (invoker, invocation, ex) -> AsyncRpcResult.newDefaultAsyncResult("fallback", invocation));

}
 
Example #6
Source File: FooConsumerBootstrap.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
public static void registryCustomFallbackForCustomException() {
    DubboFallbackRegistry.setConsumerFallback(
            (invoker, invocation, ex) -> AsyncRpcResult.newDefaultAsyncResult(new RuntimeException("fallback"), invocation));
}
 
Example #7
Source File: FooConsumerBootstrap.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
public static void registryCustomFallbackWhenFallbackError() {
    DubboFallbackRegistry.setConsumerFallback(
            (invoker, invocation, ex) -> {
                throw new RuntimeException("fallback");
            });
}
 
Example #8
Source File: FooConsumerExceptionDegradeBootstrap.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
public static void registryCustomFallback() {
    DubboFallbackRegistry.setConsumerFallback(
            (invoker, invocation, ex) -> AsyncRpcResult.newDefaultAsyncResult("fallback", invocation));

}