dubboserver+dubboclient的一个hello实例 [Dubbo实战]dubbo + zookeeper + spring 实战 +代码

本文目的:

本来网上此文极多,但是代码能直接运行的不多。这里做了一个总结

1、dubbo相关介绍(略)

2、搭建

2.1 zookeeper单机或集群(略)

2.2 dubbo server (见参考文章)

2.2 dubbo client(见参考文章)

此处说明:

1、application.xml一个名字就可以,不必分开,给自己找麻烦。

2、pom.xml建议:spring用4.x版本,maven complier pluin配置(eclipse之后版本要install jre -> jdk的方式,最新eclipse可能还需要登录授权更改)

3、client的pom引用server的jar,这样不必再重新写server中的接口代码,不用搞两份了,也不用手动打什么jar包了,maven install会打。

4、3之后,运行之前,先maven install 一下server, 然后再启动,

5、启动过程,先启动server的main, 再是client的main

 运行中zookeeper说明

运行后,在zookeeper上ls /, 发现多了dubbo节点,然后向下下钻查看,

在demoServer下,有了四个节点(consumers, souters, providers, configurators)看到都是空的,因为程序停止了。重新启动一下

 

 重新启动后,configurators还是空的,providers有了内容如下

即内容:

dubbo%3A%2F%2F10.128.6.35%3A20880%2Fcom.mor.server.dubbo.service.DemoServer%3Fanyhost%3Dtrue%26application%3Dhello-world-app%26dubbo%3D2.5.3%26interface%3Dcom.mor.server.dubbo.service.DemoServer%26methods%3DsayHello%26pid%3D2256%26side%3Dprovider%26timestamp%3D1524541239406

对照url 编码值[https://zhidao.baidu.com/question/584352067.html]

字符 - URL编码值
空格 - %20
" - %22
# - %23
% - %25
& - %26
( - %28
) - %29
+ - %2B
, - %2C
/ - %2F
: - %3A
; - %3B
< - %3C
= - %3D
> - %3E
? - %3F
@ - %40
\ - %5C
| - %7C
这个providers是
dubbo%3A%2F%2F10.128.6.35%3A20880%2Fcom.mor.server.dubbo.service.DemoServer%3Fanyhost%3Dtrue%26application%3Dhello-world-app%26dubbo%3D2.5.3%26interface%3Dcom.mor.server.dubbo.service.DemoServer%26methods%3DsayHello%26pid%3D2256%26side%3Dprovider%26timestamp%3D1524541239406

解析下来就是:

dubbo://10.128.6.35:20880/com.mor.server.dubbo.service.DemoServer?anyhost=true&application=hello-world-app&dubbo=2.5.3&interface=com.mor.server.dubbo.service.DemoServer&methods=sayHello&pid=2256&side=provider&timestamp=1524541239406

 /dubbo/com.mor.server.dubbo.service.DemoServer/routers 还是[]

/dubbo/com.mor.server.dubbo.service.DemoServer/consumers:

consumer%3A%2F%2F10.128.6.35%2Fcom.mor.server.dubbo.service.DemoServer%3Fapplication%3Dconsumer-of-helloworld-app%26category%3Dconsumers%26check%3Dfalse%26dubbo%3D2.5.3%26interface%3Dcom.mor.server.dubbo.service.DemoServer%26methods%3DsayHello%26pid%3D12848%26side%3Dconsumer%26timestamp%3D1524550888405

 

解析后:

consumer://10.128.6.35/com.mor.server.dubbo.service.DemoServer?application=consumer-of-helloworld-app&category=consumers&check=false&dubbo=2.5.3&interface=com.mor.server.dubbo.service.DemoServer&methods=sayHello&pid=12848&side=consumer&timestamp=1524550888405

 当再次启动client的时候,这个值会增加,成为[consumer://xxx, consumer://xxx, consumer://xxx, ...],会变成5个,再过会,会变成46个,那是因为参考文章里的代码在消费端重复注册了。写在外面就不会有这么多个了,应该是只有两个是正常的

参考文章

[Dubbo实战]dubbo + zookeeper + spring 实战 - CSDN博客
https://blog.csdn.net/ggibenben1314/article/details/47725241

git上已经上传代码

 https://github.com/stevenlii/dubboclient

https://github.com/stevenlii/dubboserver

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章