dubbo-async

1、接口及实现类定义超时时间

public interface HelloService {
    String hello(String name,int timeToWait);
}


@Service
public class HelloServiceImpl implements HelloService {
    @Override
    public String hello(String name,int timeToWait) {
        try {
            Thread.sleep(timeToWait);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "hello" + name;
    }
}

2、消费组配置 consumer.xml



    
    
    
    
    
    
        
    

3、消费组启动类

public class XMLConsumerMain {

    public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("consumer.xml");
        HelloService helloService = context.getBean(HelloService.class);
        while (true){
            System.in.read();
            String hello = helloService.hello("world", 100);
            //利用future模式来获取
            Future future = RpcContext.getContext().getFuture();
            System.out.println("result:" + hello);
            System.out.println("future result:" + future.get());
        }
    }
} 
  

你可能感兴趣的:(Dubbo,dubbo,java,servlet)