Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the function of FailfastClusterInvoker in dubbo

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

Today, I will talk to you about the role of FailfastClusterInvoker in dubbo. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

FailfastClusterInvoker

Dubbo-2.7.3/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/FailfastClusterInvoker.java

Public class FailfastClusterInvoker extends 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's doInvoke is wrapped as RpcException when it catches an exception and then throws a

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 performs three tests: testInvokeException, testInvokeNoException and testNoInvoke

Summary

FailfastClusterInvoker's doInvoke is wrapped as RpcException when it catches an exception and then throws a

After reading the above, do you have any further understanding of the role of FailfastClusterInvoker in dubbo? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report