dubbo learning (7) multi-version configuration

Multi-version configuration

1. Modify the service provider user implementation class

1.1 Implementation class UserServiceImpl version 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 Implementation class UserService2Impl version 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. Modify the service consumer 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. Call

http://localhost:8084/order/getUserInfo?id=1
Return: [{"password": "123456", "name": "1.0 version", "id": "1"}]

http://localhost:8084/order/getUserInfo?id=1
return: [{"password": "123456", "name": "2.0 version", "id": "1"}]

Guess you like

Origin blog.csdn.net/jinian2016/article/details/109561037