dubboe版本2.7.1
spring cloud alibaba最新官网examples
根据readme中说明文档依次启动
1、nacos,默认用户名密码nacos/nacos
2、启动spring-cloud-dubbo-server-sample,此时可以在nacos中看到发布的服务
3、启动spring-cloud-dubbo-server-sample,此处控制台会输出如下异常信息
2019-05-06 17:03:47.991 ERROR 27988 --- [ main] org.apache.dubbo.qos.server.Server : [DUBBO] qos-server can not bind localhost:22222, dubbo version: 2.7.1, current host: xxxxxxxxx
java.net.BindException: Address already in use: bind
at sun.nio.ch.Net.bind0(Native Method) ~[na:1.8.0_77]
at sun.nio.ch.Net.bind(Net.java:433) ~[na:1.8.0_77]
at sun.nio.ch.Net.bind(Net.java:425) ~[na:1.8.0_77]
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223) ~[na:1.8.0_77]
at io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:130) ~[netty-all-4.1.33.Final.jar:4.1.33.Final]
at io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:562) ~[netty-all-4.1.33.Final.jar:4.1.33.Final]
at io.netty.channel.DefaultChannelPipeline$HeadContext.bind(DefaultChannelPipeline.java:1332) ~[netty-all-4.1.33.Final.jar:4.1.33.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeBind(AbstractChannelHandlerContext.java:501) ~[netty-all-4.1.33.Final.jar:4.1.33.Final]
at io.netty.channel.AbstractChannelHandlerContext.bind(AbstractChannelHandlerContext.java:486) ~[netty-all-4.1.33.Final.jar:4.1.33.Final]
at io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:984) ~[netty-all-4.1.33.Final.jar:4.1.33.Final]
at io.netty.channel.AbstractChannel.bind(AbstractChannel.java:258) ~[netty-all-4.1.33.Final.jar:4.1.33.Final]
at io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:366) ~[netty-all-4.1.33.Final.jar:4.1.33.Final]
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute$$$capture(AbstractEventExecutor.java:163) ~[netty-all-4.1.33.Final.jar:4.1.33.Final]
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java) ~[netty-all-4.1.33.Final.jar:4.1.33.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404) ~[netty-all-4.1.33.Final.jar:4.1.33.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:495) ~[netty-all-4.1.33.Final.jar:4.1.33.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:905) ~[netty-all-4.1.33.Final.jar:4.1.33.Final]
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-all-4.1.33.Final.jar:4.1.33.Final]
at java.lang.Thread.run(Thread.java:745) ~[na:1.8.0_77]
意思就说22222这个端口已经占用了,因为在执行步骤2的时候就默认已经使用22222端口,所有在启动步骤3的时候就会出现端口被占用的情况,此异常不会影响服务的正常使用,只是qos(qos是Dubbo的在线运维命令)不能使用了。具体qos使用自行了解。
解决办法:
1、启动时添加jvm参数,不推荐
-Ddubbo.application.qos.enable=true
-Ddubbo.application.qos.port=33333
-Ddubbo.application.qos.accept.foreign.ip=false
3、spring boot应用可以在application.properties
或者application.yaml中配置上述
配置:
application.
properties:
dubbo.application.qos.enable=true
dubbo.application.qos.port=33333
dubbo.application.qos.accept.foreign.ip=false
application.yaml,注意下面的配置不是
application:
qos:
port: 33333
enable: true
accept-foreign-ip: false
PS: 网上很多说的配置要是是qosPort=xxxx,或者是qos-port=xxxx,都是不起作用的,如果用的yaml的配置方式,只能是上述的配置方式,虽然在idea会提示不能解决properties类型。
通过org.apache.dubbo.qos.protocol.QosProtocolWrapper中解析的配置如下可以正式加载方式:
private void startQosServer(URL url) {
try {
if (!hasStarted.compareAndSet(false, true)) {
return;
}
boolean qosEnable = url.getParameter("qos.enable", true);
if (!qosEnable) {
this.logger.info("qos won't be started because it is disabled. Please check dubbo.application.qos.enable is configured either in system property, dubbo.properties or XML/spring-boot configuration.");
return;
}
int port = url.getParameter("qos.port", 22222);
boolean acceptForeignIp = Boolean.parseBoolean(url.getParameter("qos.accept.foreign.ip", "false"));
Server server = Server.getInstance();
server.setPort(port);
server.setAcceptForeignIp(acceptForeignIp);
server.start();
} catch (Throwable var6) {
this.logger.warn("Fail to start qos server: ", var6);
}
}
默认加载的就是qos.port属性。