默认超时时间为1秒(1000毫秒)
消费者单个服务的超时时间限制
@DubboReference(version = "1.0.0" ,timeout = 2000)
全局设置
dubbo:consumer:timeout: 2000
测试代码:消费
@DubboReference(version = "1.0.0")public UserTestService userTestService;@Testpublic void testDubboTimeOut() throws Exception {System.out.println("Start");long startTime = System.currentTimeMillis();Result<String> result = userTestService.timeoutTest(10);long endTime = System.currentTimeMillis();System.out.println(JSON.toJSONString(result));System.out.println("End");System.out.println( endTime-startTime);}
测试代码:提供方
@DubboService(version = "1.0.0")
@Service
@Slf4j
public class UserTestServiceImpl implements UserTestService {@Overridepublic Result<String> timeoutTest(Integer second) {for (int i = 0; i < second; i++) {try {Thread.sleep(100);} catch (InterruptedException e) {e.printStackTrace();}}return Result.ok("test success");}
}