Dubbo默认超时时间

默认超时时间为1秒(1000毫秒)

消费者单个服务的超时时间限制

@DubboReference(version = "1.0.0" ,timeout = 2000)
1
全局设置

dubbo:
  consumer:
    timeout: 2000
1
2
3
测试代码:消费

    @DubboReference(version = "1.0.0")
    public UserTestService userTestService;

    @Test
    public 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);

    }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
测试代码:提供方

@DubboService(version = "1.0.0")
@Service
@Slf4j
public class UserTestServiceImpl implements UserTestService {
    @Override
    public 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");
    }

你可能感兴趣的