dubbo协议端口

Posted buguge

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了dubbo协议端口相关的知识,希望对你有一定的参考价值。

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  

 

我们看看主进程应用:

[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方法时,就会发现起不来了。异常信息:

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&register=true&release=2.7.3&side=provider&timeout=15000&timestamp=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

 

以上是关于dubbo协议端口的主要内容,如果未能解决你的问题,请参考以下文章

dubbo之本地调用

RPC和Dubbo简介

RPC和Dubbo简介

启动tomcat服务时报22222端口被占用

Dubbo配置

dubbo 配置属性