Dubbo之消费端服务RPC调用

在消费端服务是基于接口调用Provider端提供的服务,所以在消费端并没有服务公共接口的实现类。

  1. 使用过程中利用注解@DubboReference将目标接口作为某个类的字段属性,在解析该类时获取全部字段属性并单独关注解析存在注解@DubboReference的字段属性。
  2. 通过步骤1得到服务公共接口类型,在生成RootBeanDefinition时设置其Class属性为**ReferenceBean,**最终将服务公共接口注册至IOC容器中。
  3. 通过JdkDynamicAopProxy对服务公共接口生成代理。

ReferenceAnnotationBeanPostProcessor重置服务目标类在IOC注册表class的属性为ReferenceBean。

java 复制代码
public class ReferenceBean<T> implements FactoryBean<T>{
    @Override
    public T getObject() {
        if (lazyProxy == null) {
            // 对目标类代理处理
            createLazyProxy();
        }
        return (T) lazyProxy;
    }

    private void createLazyProxy() {

        ProxyFactory proxyFactory = new ProxyFactory();
        proxyFactory.setTargetSource(new DubboReferenceLazyInitTargetSource());
        proxyFactory.addInterface(interfaceClass);
        Class<?>[] internalInterfaces = AbstractProxyFactory.getInternalInterfaces();
        for (Class<?> anInterface : internalInterfaces) {
            proxyFactory.addInterface(anInterface);
        }
        if (!StringUtils.isEquals(interfaceClass.getName(), interfaceName)) {
            Class<?> serviceInterface = ClassUtils.forName(interfaceName, beanClassLoader);
            proxyFactory.addInterface(serviceInterface);
        }
        //jdk基于接口代理
        this.lazyProxy = proxyFactory.getProxy(this.beanClassLoader);
    }
}
相关推荐
励志五个月成为嵌入式糕手4 分钟前
0819 使用IP多路复用实现TCP并发服务器
java·服务器·tcp/ip
Mi_Manchikkk12 分钟前
Java高级面试实战:Spring Boot微服务与Redis缓存整合案例解析
java·spring boot·redis·缓存·微服务·面试
呼啦啦啦啦啦啦啦啦8 小时前
常见的排序算法
java·算法·排序算法
anlogic9 小时前
Java基础 8.18
java·开发语言
练习时长一年10 小时前
AopAutoConfiguration源码阅读
java·spring boot·intellij-idea
源码宝11 小时前
【智慧工地源码】智慧工地云平台系统,涵盖安全、质量、环境、人员和设备五大管理模块,实现实时监控、智能预警和数据分析。
java·大数据·spring cloud·数据分析·源码·智慧工地·云平台
David爱编程12 小时前
面试必问!线程生命周期与状态转换详解
java·后端
LKAI.12 小时前
传统方式部署(RuoYi-Cloud)微服务
java·linux·前端·后端·微服务·node.js·ruoyi
HeyZoeHey12 小时前
Mybatis执行sql流程(一)
java·sql·mybatis
2301_7930868713 小时前
SpringCloud 07 微服务网关
java·spring cloud·微服务