dubbo框架一共支持9种协议。其中,默认的,也是最常用的,那就是dubbo协议。
既然是网络协议,那么,必然要有端口号。
所以,在使用dubbo协议暴露服务时,需要配置dubbo端口。
dubbo协议的默认端口是20880。
springboot配置:
dubbo:
application:
name: omsbase-provider
registry:
address: zookeeper://192.168.40.84:${embedded.zookeeper.port}
# address: zookeeper://127.0.0.1:2181
protocol:
name: dubbo
port: 20888
一个应用程序启动后,dubbo即开启端口侦听请求。
linux服务器上查看dubbo端口:
[root@chuxing-service ~]# netstat -tunpl|grep 20880
tcp6 0 0 :::20880 :::* LISTEN 16074/java
[root@chuxing-service ~]# netstat -tunpl|grep 2088*
tcp6 0 0 :::20880 :::* LISTEN 16074/java
tcp6 0 0 :::20881 :::* LISTEN 15588/java
tcp6 0 0 :::20888 :::* LISTEN 6983/java
通过各个dubbo端口对应的pid,我们来看看相应的主进程应用:
[root@chuxing-service ~]# ps -ef|grep 16074
root 12630 11879 0 09:50 pts/1 00:00:00 grep --color=auto 16074
root 16074 1 0 Apr26 ? 00:04:31 java -Xms2g -Xmx4g -Djava.awt.headless=true -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=256m -server -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=85 -Xnoclassgc -Xverify:none -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled -jar /www/service/car-pub-server-provider/bin/../car-pub-server-provider.jar
[root@chuxing-service ~]# ps -ef|grep 15588
root 12666 11879 0 09:50 pts/1 00:00:00 grep --color=auto 15588
root 15588 1 0 Apr26 ? 00:03:44 java -Xms2g -Xmx4g -Djava.awt.headless=true -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=256m -server -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=85 -Xnoclassgc -Xverify:none -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled -jar /www/service/bosskg-server-provider/bin/../bosskg-server-provider.jar
netstat -apn/netstat -n
[root@chuxing-service ~]# netstat -apn |grep 20880
tcp6 0 0 :::20880 :::* LISTEN 16074/java
tcp6 0 0 192.168.40.84:50120 192.168.40.84:20880 ESTABLISHED 10974/java
tcp6 0 0 192.168.40.84:20880 192.168.40.84:36100 ESTABLISHED 16074/java
tcp6 0 0 192.168.40.84:36104 192.168.40.84:20880 ESTABLISHED 6983/java
tcp6 0 0 192.168.40.84:20880 192.168.40.84:50120 ESTABLISHED 16074/java
tcp6 0 0 192.168.40.84:36100 192.168.40.84:20880 ESTABLISHED 7726/java
tcp6 0 0 192.168.40.84:20880 192.168.40.84:36104 ESTABLISHED 16074/java
[root@chuxing-service ~]# netstat -n |grep 20880
tcp6 0 0 192.168.40.84:50120 192.168.40.84:20880 ESTABLISHED
tcp6 0 0 192.168.40.84:20880 192.168.40.84:36100 ESTABLISHED
tcp6 0 0 192.168.40.84:36104 192.168.40.84:20880 ESTABLISHED
tcp6 0 0 192.168.40.84:20880 192.168.40.84:50120 ESTABLISHED
tcp6 0 0 192.168.40.84:36100 192.168.40.84:20880 ESTABLISHED
tcp6 0 0 192.168.40.84:20880 192.168.40.84:36104 ESTABLISHED
注意:因为端口不能重复,所以,当一台服务器上同时存在多个应用要暴露dubbo服务时,需要指定不同的协议端口。否则的话,程序起不来。
我们可以这样模拟:一个使用了dubbo提供服务的应用程序,本地将其启动。此时,指定的端口将被占用。如果我们再运行一个testcase方法时,就会发现启动失败,提示指定的dubbo端口已经被占用。异常信息:
2020-04-24 16:26:33.231 [main] ERROR org.springframework.boot.SpringApplication:858 - Application run failed
org.apache.dubbo.rpc.RpcException: Fail to start server(url: dubbo://10.8.0.58:20888/com.emax.omsbase.rpcapi.modules.enterprise.service.EnterpriseService?anyhost=true&application=omsbase-provider&bean.name=ServiceBean:com.emax.omsbase.rpcapi.modules.enterprise.service.EnterpriseService&bind.ip=10.8.0.58&bind.port=20888&channel.readonly.sent=true&codec=dubbo&deprecated=false&dubbo=2.0.2&dynamic=true&generic=false&heartbeat=60000&interface=com.emax.omsbase.rpcapi.modules.enterprise.service.EnterpriseService&methods=checkEnterprise,saveEnterprise,saveEnterpriseProductConfig,queryIndustryType1,getPage,selectLoginAcc,queryIndustryType2,updateEnterpriseById,updateEntStatusByEntId,resetEntAccountPasswordByEntId,openEnterpriseByEntId,updateEnterpriseProductConfigById,updateEnterpriseBillConfigById&pid=21060&qos.enable=false®ister=true&release=2.7.3&side=provider&timeout=15000×tamp=1587716790773) Failed to bind NettyServer on /10.8.0.58:20888, cause: Address already in use: bind
...
Caused by: org.apache.dubbo.remoting.RemotingException: Failed to bind NettyServer on /10.8.0.58:20888, cause: Address already in use: bind
...
Caused by: java.net.BindException: Address already in use: bind
动力节点在线课程涵盖零基础入门,高级进阶,在职提升三大主力内容,覆盖Java从入门到就业提升的全体系学习内容。全部Java教程免费观看,相关学习资料免费下载!对于火爆技术,每周一定时更新!如果想了解更多相关技术,可以到动力节点在线免费观看Dubbo框架视频教程学习哦!
提枪策马乘胜追击04-21 20:01
代码小兵92504-17 16:07
代码小兵98804-25 13:57
杨晶珍05-11 14:54