dubbo中FailfastClusterInvoker的作用是什么
发表于:2025-02-05 作者:千家信息网编辑
千家信息网最后更新 2025年02月05日,今天就跟大家聊聊有关dubbo中FailfastClusterInvoker的作用是什么,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。Fail
千家信息网最后更新 2025年02月05日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的作用是什么有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注行业资讯频道,感谢大家的支持。
内容
作用
时候
包装
小结
更多
知识
篇文章
行业
资讯
资讯频道
频道
进一
支持
有关
测试
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
数据库技术英文怎么说
智能汽车空调控制软件开发
房产小程序用什么服务器
独立软件开发者可以同时使用吗
计算机服务器的管理与维护
网络安全技术李卓玲
江苏家用软件开发定制价格
服务器可以运行阿里云吗
运用数据库管理客户信息的优点
网络安全达成协议
南昌闻微互联网科技
惠州蓝库网络技术有限公司
安全网络服务器
哪些erp软件基于sql数据库
刀片服务器
云南云主机集群管理服务器
qq一直更新数据库
关于数据库系统安全论文题目
数据库时间用什么格式
数据库查询数组内
特斯拉上海软件开发招聘
山西在线网络技术服务售价
汇丰高级软件开发工程师
rsync 服务器配置
软件设计师和数据库工程师哪个好
不同数据库查询的结果怎样
云服务器管理和运维
mysql数据库 修复
护航网络安全工作
我的理想是软件开发