皆非的万事屋

RPC理解,Dubbo和Feign的对比

RPC

随着公司规模的扩大,以及业务量的激增,单体应用逐步演化为服务/微服务的架构模式,因此便会产生不同服务之间相互调用的情况,而 服务之间的调用大多采用rpc的方式调用

概述

Dubbo

//dubbo里的@Service注解
import org.apache.dubbo.config.annotation.Service;

@Service
public class AppServiceImpl implements IAppService {
    @Autowired
    AppMapper appMapper;
    @Override
    public AppDTO createApp(AppDTO appDTO) throws BizException {
        return null;
    }
@Slf4j
@RestController
public class AppController {
//远程调用
    @Reference
    IAppService appService;

    public AppDTO createApp(@RequestBody AppVo appVo){
        return appService.createApp(appDTO);
    }


Feign

问题 Feign算不算RPC框架?

新生电子报道

点赞

@Service
@Slf4j
@RequiredArgsConstructor
public class StudentPraiseServiceImpl extends ServiceImpl<StudentPraiseMapper, StudentPraise> implements IStudentPraiseService {

    private final StudentPraiseMapper studentPraiseMapper;

    private final IStudentsService studentsService;

    private final IOpenIdService openIdService;

    @Override
    @GlobalTransactional
    public Boolean clickWish( String cartId, String openId ) {
        log.info("【学生身份证为:】" + cartId + "【当前用户的openid为】" + openId);
        Integer openIdCount = openIdService.selectCount(openId);
        if (openIdCount != 0) {
            Students students = studentsService.getByCartId(cartId);
            Integer id = students.getId();
            //将openid和考生id插入
            QueryWrapper<StudentPraise> studentPraiseWrapper = new QueryWrapper<>();
            studentPraiseWrapper.lambda().eq(StudentPraise::getStudentId, id).eq(StudentPraise::getOpenid, openId);
            Integer count = studentPraiseMapper.selectCount(studentPraiseWrapper);
            if (count == 0) {
                StudentPraise studentPraise = new StudentPraise();
                studentPraise.setStudentId(id);
                studentPraise.setOpenid(openId);
                studentPraiseMapper.insert(studentPraise);
                log.info("【插入数据成功】");
                //查询当前的祝福数量
                Students selectOne = studentsService.getById(id);
                int wishes = 0;
                if (ObjectUtil.isNotNull(selectOne)) {
                    if (ObjectUtil.isNotNull(selectOne.getWishes())) {
                        wishes = selectOne.getWishes();
                    }
                }
                log.info("【当前的祝福数量为:】" + wishes);
                //更新库中的祝福数量
                return studentsService.updateWishesById(id, wishes+1);
            } else {
                return false;
            }
        } else {
            return null;
        }
    }
}

大屏展示

问题 公网ip与内网ip

当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »