org.apache.dubbo.rpc.AsyncRpcResult Java Examples
The following examples show how to use
org.apache.dubbo.rpc.AsyncRpcResult.
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: ApacheMonitorFilterAdvice.java From apm-agent-java with Apache License 2.0 | 6 votes |
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class) public static void onExitFilterInvoke(@Advice.Argument(1) Invocation invocation, @Advice.Return Result result, @Nullable @Advice.Local("span") final Span span, @Advice.Thrown Throwable t, @Nullable @Advice.Local("transaction") Transaction transaction) { RpcContext context = RpcContext.getContext(); AbstractSpan<?> actualSpan = context.isConsumerSide() ? span : transaction; if (actualSpan == null) { return; } actualSpan.deactivate(); if (result instanceof AsyncRpcResult) { AsyncCallbackCreator callbackCreator = asyncCallbackCreatorClassManager.getForClassLoaderOfClass(Result.class); if (callbackCreator == null) { actualSpan.end(); return; } context.set(DubboTraceHelper.SPAN_KEY, actualSpan); result.whenCompleteWithContext(callbackCreator.create(actualSpan)); } else { actualSpan.end(); } }
Example #2
Source File: DubboFallbackRegistryTest.java From Sentinel with Apache License 2.0 | 5 votes |
@Test public void testCustomFallback() { BlockException ex = new FlowException("xxx"); DubboFallbackRegistry.setConsumerFallback( (invoker, invocation, e) -> AsyncRpcResult.newDefaultAsyncResult("Error: " + e.getClass().getName(), invocation)); Result result = DubboFallbackRegistry.getConsumerFallback() .handle(null, null, ex); Assert.assertFalse("The invocation should not fail", result.hasException()); Assert.assertEquals("Error: " + ex.getClass().getName(), result.getValue()); }
Example #3
Source File: SentinelDubboConsumerFilterTest.java From Sentinel with Apache License 2.0 | 5 votes |
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: SentinelDubboConsumerFilterTest.java From Sentinel with Apache License 2.0 | 5 votes |
private Result invokeDubboRpc(boolean exception, Invoker invoker, Invocation invocation) { Result result = null; InvokeMode invokeMode = RpcUtils.getInvokeMode(invoker.getUrl(), invocation); if (InvokeMode.SYNC == invokeMode) { result = exception ? new AppResponse(new Exception("error")) : new AppResponse("normal"); } else { result = exception ? AsyncRpcResult.newDefaultAsyncResult(new Exception("error"), invocation) : AsyncRpcResult.newDefaultAsyncResult("normal", invocation); } when(invoker.invoke(invocation)).thenReturn(result); return consumerFilter.invoke(invoker, invocation); }
Example #5
Source File: FooConsumerBootstrap.java From Sentinel with Apache License 2.0 | 4 votes |
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 |
public static void registryCustomFallbackForCustomException() { DubboFallbackRegistry.setConsumerFallback( (invoker, invocation, ex) -> AsyncRpcResult.newDefaultAsyncResult(new RuntimeException("fallback"), invocation)); }
Example #7
Source File: FooConsumerExceptionDegradeBootstrap.java From Sentinel with Apache License 2.0 | 4 votes |
public static void registryCustomFallback() { DubboFallbackRegistry.setConsumerFallback( (invoker, invocation, ex) -> AsyncRpcResult.newDefaultAsyncResult("fallback", invocation)); }
Example #8
Source File: MyInvoker.java From dubbo-samples with Apache License 2.0 | 4 votes |
@Override public org.apache.dubbo.rpc.Result invoke(Invocation invocation) throws org.apache.dubbo.rpc.RpcException { return AsyncRpcResult.newDefaultAsyncResult("hello", invocation); }