dubbo学习(七)多版本配置

多版本配置

1. 修改服务提供者 user实现类

1.1 实现类 UserServiceImpl 版本1.0

@DubboService(version = "1.0")
@Service
public class UserServiceImpl implements UserService {
    
    

    /**
     * @param id 查询用户列表
     * @return
     */
    @Override
    public List<Map> getUserList(String id) {
    
    
        List<Map> returnList = new ArrayList<>();

        Map<String,Object> item = new HashMap<>();
        item.put("id",id);
        item.put("name","1.0版本");
        item.put("password","123456");
        returnList.add(item);
       /* try {
            Thread.sleep(4000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }*/
        return returnList;
    }
}

1.2 实现类 UserService2Impl 版本2.0

@DubboService(version = "2.0")
@Service
public class UserService2Impl implements UserService {
    
    

    /**
     * @param id 查询用户列表
     * @return
     */
    @Override
    public List<Map> getUserList(String id) {
    
    
        List<Map> returnList = new ArrayList<>();

        Map<String,Object> item = new HashMap<>();
        item.put("id",id);
        item.put("name","2.0版本");
        item.put("password","123456");
        returnList.add(item);
       /* try {
            Thread.sleep(4000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }*/
        return returnList;
    }
}

2. 修改服务消费者 order

@DubboReference(check = false,timeout = 3000,retries = 3,version = "1.0")
    private UserService userService;
@DubboReference(check = false,timeout = 3000,retries = 3,version = "2.0")
    private UserService userService;

3. 调用

http://localhost:8084/order/getUserInfo?id=1
返回:[{“password”:“123456”,“name”:“1.0版本”,“id”:“1”}]

http://localhost:8084/order/getUserInfo?id=1
返回:[{“password”:“123456”,“name”:“2.0版本”,“id”:“1”}]

猜你喜欢

转载自blog.csdn.net/jinian2016/article/details/109561037