dubbo服务导出的本质
Posted bruce128
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了dubbo服务导出的本质相关的知识,希望对你有一定的参考价值。
当注册中心是zookeeper的时候,服务导出其实是在/root/interface/providers下创建一个临时节点,这个节点的路径就是服务的url。而取消注册就是将该节点删除。
// 服务注册
@Override
public void doRegister(URL url)
try
// 创建临时节点
zkClient.create(toUrlPath(url), url.getParameter(DYNAMIC_KEY, true));
catch (Throwable e)
throw new RpcException("Failed to register " + url + " to zookeeper " + getUrl() + ", cause: " + e.getMessage(), e);
// 服务下线
@Override
public void doUnregister(URL url)
try
// 把对应节点删除
zkClient.delete(toUrlPath(url));
catch (Throwable e)
throw new RpcException("Failed to unregister " + url + " to zookeeper " + getUrl() + ", cause: " + e.getMessage(), e);
注册的URL示例
dubbo://192.168.2.100:25000/org.dubbo.server.api.DemoService?anyhost=true&application=hehe_consumer&async=false&cluster=failover&deprecated=false&dubbo=2.0.2&dynamic=true&generic=false&group=IM-CELL-ACCESS-192.168.2.100-25000&heartbeat=0&interface=org.dubbo.server.api.DemoService&loadbalance=roundrobin&methods=sayHello&organization=risk.im.jd.com&owner=lvsheng&pid=97790&release=2.7.5&retries=3&side=provider&threadpool=cached&threads=512&timeout=5000×tamp=1578388804546
用zkClient查看
[zk: localhost:2181(CONNECTED) 42] ls /dubbo/org.dubbo.server.api.DemoService/providers
[dubbo%3A%2F%2F192.168.2.100%3A25000%2Forg.dubbo.server.api.DemoService%3Fanyhost%3Dtrue%26application%3Dhehe_consumer%26async%3Dfalse%26cluster%3Dfailover%26deprecated%3Dfalse%26dubbo%3D2.0.2%26dynamic%3Dtrue%26generic%3Dfalse%26group%3DIM-CELL-ACCESS-192.168.2.100-25000%26heartbeat%3D0%26interface%3Dorg.dubbo.server.api.DemoService%26loadbalance%3Droundrobin%26methods%3DsayHello%26organization%3Drisk.im.jd.com%26owner%3Dlvsheng%26pid%3D97790%26release%3D2.7.5%26retries%3D3%26side%3Dprovider%26threadpool%3Dcached%26threads%3D512%26timeout%3D5000%26timestamp%3D1578388804546]
以上是关于dubbo服务导出的本质的主要内容,如果未能解决你的问题,请参考以下文章