dubbo 中的默认超时是 1000 毫秒。

在 consumer 模块中 dubbo-consumer.xml 配置 timeout :

<dubbo:reference id="demoService" interface="demo.contract.DemoService" check="false" timeout="2000"/>

运行 ConsumerMain,会看到:

Exception in thread “main” org.apache.dubbo.rpc.RpcException: Failed to invoke the method sayHello in the service demo.contract.DemoService. Tried 3 times of the providers [127.0.0.1:20881] (1/1) from the registry 127.0.0.1:2181 on the consumer 127.0.0.1 using the dubbo version 2.7.1. Last error is: Invoke remote method timeout. method: sayHello, provider: dubbo://127.0.0.1:20881/demo.contract….
….
Caused by: org.apache.dubbo.remoting.TimeoutException: Waiting server-side response timeout by scan timer.

为什么是 Tried 3 times ? 因为 retries 参数默认值是 2 。正常的1次加上重试的2次,一共3次。要修改重试次数,可以:

<dubbo:reference id=”demoService”
interface=”demo.contract.DemoService”
check=”false” timeout=”2000″ retries=”3″/>

配置 provider 超时

去掉上面 dubbo-consumer.xml 中配置的超时,在 dubbo-provider.xml 中配置 timeout:

<dubbo:service interface=”demo.contract.DemoService” class=”demo.provider.DemoServiceImpl” timeout=”2000″/>

Exception in thread “main” org.apache.dubbo.rpc.RpcException: Failed to invoke the method sayHello in the service demo.contract.DemoService. Tried 3 times of the providers [127.0.0.1:20881] (1/1) from the registry 127.0.0.1:2181 on the consumer 127.0.0.1 using the dubbo version 2.7.1. Last error is: Invoke remote method timeout.

aused by: org.apache.dubbo.remoting.TimeoutException: Waiting server-side response timeout.

优先级

如果 provider 配置超时为 6000,consumer 配置超时为 2000,报超时错误。

如果 provider 配置超时为 2000,consumer 配置超时为 6000,正常运行,不会报超时错误。

可见,consumer超时和provider超时无法共存,consumer超时优先provider。

一般建议在 provider 配置超时,因为 provider 更清楚要配置为多少。consumer 配置的超时要参考 provider 配置的值。

默认全局超时

可以用 <dubbo:provider /> 配置 provider 的全局超时;用 <dubbo:consumer/> 在 consumer 侧配置超时。

例如:

<dubbo:provider timeout=”2000″/>

  1. I am also commenting to let you know of the great encounter my friend’s daughter found reading through your web page. She figured out numerous issues, not to mention what it’s like to have an amazing giving mood to have men and women really easily have an understanding of selected hard to do subject areas. You really exceeded our own expectations. Many thanks for imparting the interesting, safe, explanatory and even easy thoughts on the topic to Janet.

  2. I happen to be writing to make you understand what a useful experience our princess went through visiting yuor web blog. She realized too many things, with the inclusion of what it is like to possess an incredible teaching style to make the rest without problems understand various very confusing topics. You undoubtedly surpassed visitors’ expected results. Thanks for supplying those warm and friendly, trustworthy, revealing not to mention unique tips on your topic to Tanya.

  3. I am also writing to make you know what a incredible encounter my friend’s girl gained reading through your web page. She learned plenty of pieces, which include what it’s like to possess an amazing helping mood to let other folks smoothly thoroughly grasp various tricky topics. You undoubtedly surpassed visitors’ expected results. Thanks for showing those warm and friendly, trustworthy, revealing not to mention unique tips on your topic to Sandra.

  4. I simply needed to thank you so much once again. I am not sure the things that I would’ve implemented without the type of recommendations provided by you on such a question. It previously was a very frightful dilemma in my opinion, however , noticing the very specialised mode you processed that made me to leap over gladness. I am just happy for this information and in addition hope that you know what a great job you are always getting into teaching people thru your web blog. More than likely you have never got to know any of us.

  5. I happen to be writing to make you understand what a useful experience our princess went through visiting yuor web blog. She realized too many things, with the inclusion of what it is like to possess an incredible teaching style to make the rest without problems understand various very confusing topics. You undoubtedly surpassed visitors’ expected results. Thanks for supplying those warm and helpful, trustworthy, revealing not to mention unique tips on your topic to Tanya.

  6. I enjoy you because of all of your efforts on this site. Ellie enjoys doing internet research and it’s easy to see why. All of us hear all concerning the compelling manner you deliver good information by means of the blog and as well cause contribution from other people about this concept plus my daughter is being taught a lot. Enjoy the remaining portion of the new year. You’re the one carrying out a first class job.

  7. Thank you for every one of your labor on this web site. My daughter really loves managing investigations and it’s really obvious why. Most people learn all regarding the lively mode you present rewarding techniques through this web site and even inspire participation from some others on the point then our favorite princess is really starting to learn a whole lot. Take advantage of the rest of the year. You are always doing a splendid job.

  8. I am just writing to make you understand what a outstanding experience my wife’s girl obtained using your webblog. She noticed so many pieces, which included what it is like to possess an excellent helping spirit to let other people with no trouble learn specific specialized things. You truly surpassed readers’ expected results. Thank you for providing these priceless, trusted, informative as well as fun tips about this topic to Lizeth.

Leave a Reply

电子邮件地址不会被公开。 必填项已用*标注