dubboe版本2.7.1java
spring cloud alibaba最新官網examplesspring
根據readme中說明文檔依次啓動apache
一、nacos,默認用戶名密碼nacos/nacosbootstrap
二、啓動spring-cloud-dubbo-server-sample,此時能夠在nacos中看到發佈的服務app
三、啓動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使用自行了解。jvm
解決辦法:socket
一、啓動時添加jvm參數,不推薦ide
-Ddubbo.application.qos.enable=true
-Ddubbo.application.qos.port=33333
-Ddubbo.application.qos.accept.foreign.ip=false
三、spring boot應用能夠在application.properties
或者application.yaml中配置上述
配置:spring-boot
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屬性。