dubbo中FailfastClusterInvoker的作用是什么
今天就跟大家聊聊有关dubbo中FailfastClusterInvoker的作用是什么,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
站在用户的角度思考问题,与客户深入沟通,找到南川网站设计与南川网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:网站制作、成都网站建设、企业官网、英文网站、手机端网站、网站推广、主机域名、网站空间、企业邮箱。业务覆盖南川地区。
FailfastClusterInvoker
dubbo-2.7.3/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/FailfastClusterInvoker.java
public class FailfastClusterInvokerextends AbstractClusterInvoker { public FailfastClusterInvoker(Directory directory) { super(directory); } @Override public Result doInvoke(Invocation invocation, List > invokers, LoadBalance loadbalance) throws RpcException { checkInvokers(invokers, invocation); Invoker invoker = select(loadbalance, invocation, invokers, null); try { return invoker.invoke(invocation); } catch (Throwable e) { if (e instanceof RpcException && ((RpcException) e).isBiz()) { // biz exception. throw (RpcException) e; } throw new RpcException(e instanceof RpcException ? ((RpcException) e).getCode() : 0, "Failfast invoke providers " + invoker.getUrl() + " " + loadbalance.getClass().getSimpleName() + " select from all providers " + invokers + " for service " + getInterface().getName() + " method " + invocation.getMethodName() + " on consumer " + NetUtils.getLocalHost() + " use dubbo version " + Version.getVersion() + ", but no luck to perform the invocation. Last error is: " + e.getMessage(), e.getCause() != null ? e.getCause() : e); } } }
FailfastClusterInvoker的doInvoke在捕获到异常的时候包装为RpcException然后再抛出
FailfastClusterInvokerTest
dubbo-2.7.3/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/FailfastClusterInvokerTest.java
public class FailfastClusterInvokerTest { List> invokers = new ArrayList >(); URL url = URL.valueOf("test://test:11/test"); Invoker invoker1 = mock(Invoker.class); RpcInvocation invocation = new RpcInvocation(); Directory dic; Result result = new AppResponse(); /** * @throws java.lang.Exception */ @BeforeEach public void setUp() throws Exception { dic = mock(Directory.class); given(dic.getUrl()).willReturn(url); given(dic.list(invocation)).willReturn(invokers); given(dic.getInterface()).willReturn(FailfastClusterInvokerTest.class); invocation.setMethodName("method1"); invokers.add(invoker1); } private void resetInvoker1ToException() { given(invoker1.invoke(invocation)).willThrow(new RuntimeException()); given(invoker1.getUrl()).willReturn(url); given(invoker1.getInterface()).willReturn(FailfastClusterInvokerTest.class); } private void resetInvoker1ToNoException() { given(invoker1.invoke(invocation)).willReturn(result); given(invoker1.getUrl()).willReturn(url); given(invoker1.getInterface()).willReturn(FailfastClusterInvokerTest.class); } @Test public void testInvokeException() { Assertions.assertThrows(RpcException.class, () -> { resetInvoker1ToException(); FailfastClusterInvoker invoker = new FailfastClusterInvoker (dic); invoker.invoke(invocation); Assertions.assertSame(invoker1, RpcContext.getContext().getInvoker()); }); } @Test() public void testInvokeNoException() { resetInvoker1ToNoException(); FailfastClusterInvoker invoker = new FailfastClusterInvoker (dic); Result ret = invoker.invoke(invocation); Assertions.assertSame(result, ret); } @Test() public void testNoInvoke() { dic = mock(Directory.class); given(dic.getUrl()).willReturn(url); given(dic.list(invocation)).willReturn(null); given(dic.getInterface()).willReturn(FailfastClusterInvokerTest.class); invocation.setMethodName("method1"); invokers.add(invoker1); resetInvoker1ToNoException(); FailfastClusterInvoker invoker = new FailfastClusterInvoker (dic); try { invoker.invoke(invocation); fail(); } catch (RpcException expected) { assertFalse(expected.getCause() instanceof RpcException); } } }
FailfastClusterInvokerTest执行了testInvokeException、testInvokeNoException、testNoInvoke三种测试
小结
FailfastClusterInvoker的doInvoke在捕获到异常的时候包装为RpcException然后再抛出
看完上述内容,你们对dubbo中FailfastClusterInvoker的作用是什么有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联行业资讯频道,感谢大家的支持。
网站题目:dubbo中FailfastClusterInvoker的作用是什么
浏览地址:http://ybzwz.com/article/pdgseg.html