美文网首页
Dubbo - Consumer消费者

Dubbo - Consumer消费者

作者: 沐兮_d64c | 来源:发表于2019-05-26 17:12 被阅读0次

1,消费者端简单配置和使用

1)consumer-first.xml 消费者配置

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
       xmlns="http://www.springframework.org/schema/beans"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">

    <dubbo:application name="demo-consumer-first"/>

    <!-- 集群配置<dubbo:registry address="zookeeper://10.20.153.10:2181?backup=10.20.153.11:2181,10.20.153.12:2181" /> -->
    <!-- 单节点配置 -->
    <dubbo:registry id="hzqDubboV1" protocol="zookeeper" address="127.0.0.1:2181" />

    <dubbo:reference id="demoService" interface="com.hzq.IDemoService"/>

</beans>

2)执行rpc调用


image.png

2,Consumer执行RPC调用的过程

1)consumer端,持有provider端服务的Proxy代理类。
ReferenceBean在afterPropertiesSet方法中,getObject(); -> ReferenceConfig.init() 方法,createProxy创建代理。调用DubboProtocol的refer方法创建DubboInvoker
从注册中心获取URL,创建对应的Invoker对象。

image.png
create service proxy,consumer端创建出Proxy对象
image.png
2)使用Proxy对象调用方法时,会dispatch到InvokerInvocationHandler的invoke方法。
JdkProxyFactory与InvokerInvocationHandler
image.png
image.png
3)使用AbstractClusterInvoker的invoke
image.png
几种Invoker
image.png
4)最终调用DubboInvoker的doInvoker的过程
将Invocation发送给服务端,服务端找到本地Invoker,反射执行对应的方法,再将结果返回。
image.png

相关文章

网友评论

      本文标题:Dubbo - Consumer消费者

      本文链接:https://www.haomeiwen.com/subject/pwhftctx.html