Role-based access control (RBAC) is a method of regulating access to computer or network resources based on the roles of individual users within an enterprise. In this context, access is the ability of an individual user to perform a specific task, such as view, create, or modify a file.
(The National Institute of Standards and Technology,美国国家标准与技术研究院)标准RBAC模型由4个部件模型组成,这4个部件模型分别是:
Spring 依赖注入很简单,没什么值得细说的。但是我之前遇到了一个场景,需要在一个Enum类中注入某一个service。 说实话之前没有遇到过这种情况。虽然我不赞同Enum类有过多的逻辑,但是没有办法,现实就是那么残酷。而且Enum确实可以通过一些手段来注入其他发service的。 比如下面的代码中,为EnumClass枚举类注入OtherService服务,代码示例如下:
wget http://archive.apache.org/dist/zookeeper/zookeeper-3.3.3/zookeeper-3.3.3.tar.gz tar zxvf zookeeper-3.3.3.tar.gz cd zookeeper-3.3.3 cp conf/zoo_sample.cfg conf/zoo.cfg
@echo off REM Licensed to the Apache Software Foundation (ASF) under one or more REM contributor license agreements. See the NOTICE file distributed with REM this work for additional information regarding copyright ownership. REM The ASF licenses this file to You under the Apache License, Version 2.0 REM (the "License"); you may not use this file except in compliance with REM the License. You may obtain a copy of the License at REM REM http://www.apache.org/licenses/LICENSE-2.0 REM REM Unless required by applicable law or agreed to in writing, software REM distributed under the License is distributed on an "AS IS" BASIS, REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. REM See the License for the specific language governing permissions and REM limitations under the License.
setlocal call "%~dp0zkEnv.cmd"
set ZOOMAIN=org.apache.zookeeper.server.quorum.QuorumPeerMain echo on call %JAVA% "-Dzookeeper.log.dir=%ZOO_LOG_DIR%" "-Dzookeeper.root.logger=%ZOO_LOG4J_PROP%" -cp "%CLASSPATH%" %ZOOMAIN% "%ZOOCFG%" %*
<!-- provider's application name, used for tracing dependency relationship --> <dubbo:applicationname="demo-provider"/>
<!-- use multicast registry center to export service --> <!--<dubbo:registry address="multicast://224.5.6.7:1234"/>--> <dubbo:registryprotocol="zookeeper"address="localhost:2181"/>
<!-- use dubbo protocol to export service on port 20880 --> <dubbo:protocolname="dubbo"port="20880"/>
<!-- service implementation, as same as regular local bean --> <beanid="demoService"class="org.apache.dubbo.demo.provider.DemoServiceImpl"/>
<!-- declare the service interface to be exported --> <dubbo:serviceinterface="org.apache.dubbo.demo.DemoService"ref="demoService"/>
</beans>
安装dubbo
其实就是下载dubbo的源码以及对应的maven依赖:
1 2 3 4
git clone https://github.com/apache/incubator-dubbo.git cd incubator-dubbo 运行 dubbo-demo-provider中的com.alibaba.dubbo.demo.provider.Provider 如果使用Intellij Idea 请加上-Djava.net.preferIPv4Stack=true
Connected to the target VM, address: '127.0.0.1:7562', transport: 'socket' [20/08/1811:43:20:020 CST] main INFO support.ClassPathXmlApplicationContext: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@551aa95a: startup date [Mon Aug 2023:43:20 CST 2018]; root of context hierarchy [20/08/18 11:43:20:020 CST] main INFO xml.XmlBeanDefinitionReader: Loading XML bean definitions from class path resource [META-INF/spring/dubbo-demo-provider.xml] [20/08/1811:43:20:020 CST] main INFO logger.LoggerFactory: using logger: org.apache.dubbo.common.logger.log4j.Log4jLoggerAdapter [20/08/1811:43:20:020 CST] main WARN extension.SpringExtensionFactory: [DUBBO] No spring extension(bean) named:defaultCompiler, try to find an extension(bean) of type java.lang.String, dubbo version: , current host: 192.168.116.1 [20/08/18 11:43:20:020 CST] main WARN extension.SpringExtensionFactory: [DUBBO] No spring extension(bean) named:defaultCompiler, type:java.lang.String found, stop get bean., dubbo version: , current host: 192.168.116.1 [20/08/18 11:43:20:020 CST] main INFO config.AbstractConfig: [DUBBO] The service ready on spring started. service: org.apache.dubbo.demo.DemoService, dubbo version: , current host: 192.168.116.1 [20/08/18 11:43:21:021 CST] main INFO config.AbstractConfig: [DUBBO] Export dubbo service org.apache.dubbo.demo.DemoService to local registry, dubbo version: , current host: 192.168.116.1 [20/08/18 11:43:21:021 CST] main INFO config.AbstractConfig: [DUBBO] Export dubbo service org.apache.dubbo.demo.DemoService to url dubbo://192.168.116.1:20880/org.apache.dubbo.demo.DemoService?anyhost=true&application=demo-provider&bind.ip=192.168.116.1&bind.port=20880&dubbo=2.0.2&generic=false&interface=org.apache.dubbo.demo.DemoService&methods=sayHello&pid=6872&qos.port=22222&side=provider×tamp=1534779801013, dubbo version: , current host: 192.168.116.1 [20/08/18 11:43:21:021 CST] main INFO config.AbstractConfig: [DUBBO] Register dubbo service org.apache.dubbo.demo.DemoService url dubbo://192.168.116.1:20880/org.apache.dubbo.demo.DemoService?anyhost=true&application=demo-provider&bind.ip=192.168.116.1&bind.port=20880&dubbo=2.0.2&generic=false&interface=org.apache.dubbo.demo.DemoService&methods=sayHello&pid=6872&qos.port=22222&side=provider×tamp=1534779801013 to registry registry://localhost:2181/org.apache.dubbo.registry.RegistryService?application=demo-provider&dubbo=2.0.2&pid=6872&qos.port=22222®istry=zookeeper×tamp=1534779801006, dubbo version: , current host: 192.168.116.1 [20/08/18 11:43:22:022 CST] main INFO transport.AbstractServer: [DUBBO] Start NettyServer bind /0.0.0.0:20880, export /192.168.116.1:20880, dubbo version: , current host: 192.168.116.1 [20/08/18 11:43:22:022 CST] main INFO zookeeper.ZookeeperRegistry: [DUBBO] Load registry store file C:\Users\wenchao.ren\.dubbo\dubbo-registry-demo-provider-localhost:2181.cache, data: {org.apache.dubbo.demo.DemoService=empty://192.168.116.1:20880/org.apache.dubbo.demo.DemoService?anyhost=true&application=demo-provider&category=configurators&check=false&dubbo=2.0.2&generic=false&interface=org.apache.dubbo.demo.DemoService&methods=sayHello&pid=18588&side=provider×tamp=1534778576083}, dubbo version: , current host: 192.168.116.1 [20/08/1811:43:22:022 CST] main INFO imps.CuratorFrameworkImpl: Starting [20/08/1811:43:22:022 CST] main INFO zookeeper.ZooKeeper: Client environment:zookeeper.version=3.4.9-1757313, built on 08/23/201606:50 GMT [20/08/1811:43:22:022 CST] main INFO zookeeper.ZooKeeper: Client environment:host.name=c [20/08/1811:43:22:022 CST] main INFO zookeeper.ZooKeeper: Client environment:java.version=1.8.0_181 [20/08/1811:43:22:022 CST] main INFO zookeeper.ZooKeeper: Client environment:java.vendor=Oracle Corporation [20/08/1811:43:22:022 CST] main INFO zookeeper.ZooKeeper: Client environment:java.home=C:\Program Files\Java\jdk1.8.0_181\jre [20/08/1811:43:22:022 CST] main INFO zookeeper.ZooKeeper: Client environment:java.class.path=C:\Program Files\Java\jdk1.8.0_181\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\rt.jar;E:\workstations\dubbo\incubator-dubbo\dubbo-demo\dubbo-demo-provider\target\classes;E:\workstations\dubbo\incubator-dubbo\dubbo-demo\dubbo-demo-api\target\classes;E:\workstations\dubbo\incubator-dubbo\dubbo-config\dubbo-config-spring\target\classes;E:\workstations\dubbo\incubator-dubbo\dubbo-config\dubbo-config-api\target\classes;E:\workstations\dubbo\incubator-dubbo\dubbo-monitor\dubbo-monitor-api\target\classes;E:\workstations\dubbo\incubator-dubbo\dubbo-filter\dubbo-filter-validation\target\classes;C:\Users\wenchao.ren\.m2\repository\javax\validation\validation-api\1.1.0.Final\validation-api-1.1.0.Final.jar;E:\workstations\dubbo\incubator-dubbo\dubbo-filter\dubbo-filter-cache\target\classes;C:\Users\wenchao.ren\.m2\repository\javax\cache\cache-api\1.0.0\cache-api-1.0.0.jar;E:\workstations\dubbo\incubator-dubbo\dubbo-bootstrap\target\classes;E:\workstations\dubbo\incubator-dubbo\dubbo-common\target\classes;C:\Users\wenchao.ren\.m2\repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;C:\Users\wenchao.ren\.m2\repository\log4j\log4j\1.2.16\log4j-1.2.16.jar;C:\Users\wenchao.ren\.m2\repository\org\javassist\javassist\3.20.0-GA\javassist-3.20.0-GA.jar;C:\Users\wenchao.ren\.m2\repository\org\springframework\spring-beans\4.3.16.RELEASE\spring-beans-4.3.16.RELEASE.jar;C:\Users\wenchao.ren\.m2\repository\org\springframework\spring-core\4.3.16.RELEASE\spring-core-4.3.16.RELEASE.jar;C:\Users\wenchao.ren\.m2\repository\org\springframework\spring-web\4.3.16.RELEASE\spring-web-4.3.16.RELEASE.jar;C:\Users\wenchao.ren\.m2\repository\org\springframework\spring-aop\4.3.16.RELEASE\spring-aop-4.3.16.RELEASE.jar;C:\Users\wenchao.ren\.m2\repository\org\springframework\spring-context\4.3.16.RELEASE\spring-context-4.3.16.RELEASE.jar;C:\Users\wenchao.ren\.m2\repository\org\springframework\spring-expression\4.3.16.RELEASE\spring-expression-4.3.16.RELEASE.jar;E:\workstations\dubbo\incubator-dubbo\dubbo-rpc\dubbo-rpc-injvm\target\classes;E:\workstations\dubbo\incubator-dubbo\dubbo-registry\dubbo-registry-zookeeper\target\classes;E:\workstations\dubbo\incubator-dubbo\dubbo-registry\dubbo-registry-api\target\classes;E:\workstations\dubbo\incubator-dubbo\dubbo-cluster\target\classes;E:\workstations\dubbo\incubator-dubbo\dubbo-remoting\dubbo-remoting-zookeeper\target\classes;C:\Users\wenchao.ren\.m2\repository\org\apache\zookeeper\zookeeper\3.4.9\zookeeper-3.4.9.jar;C:\Users\wenchao.ren\.m2\repository\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;C:\Users\wenchao.ren\.m2\repository\org\slf4j\slf4j-log4j12\1.6.1\slf4j-log4j12-1.6.1.jar;C:\Users\wenchao.ren\.m2\repository\jline\jline\0.9.94\jline-0.9.94.jar;C:\Users\wenchao.ren\.m2\repository\io\netty\netty\3.10.5.Final\netty-3.10.5.Final.jar;C:\Users\wenchao.ren\.m2\repository\com\101tec\zkclient\0.2\zkclient-0.2.jar;C:\Users\wenchao.ren\.m2\repository\org\apache\curator\curator-framework\2.12.0\curator-framework-2.12.0.jar;C:\Users\wenchao.ren\.m2\repository\org\apache\curator\curator-client\2.12.0\curator-client-2.12.0.jar;C:\Users\wenchao.ren\.m2\repository\com\google\guava\guava\16.0.1\guava-16.0.1.jar;E:\workstations\dubbo\incubator-dubbo\dubbo-registry\dubbo-registry-multicast\target\classes;E:\workstations\dubbo\incubator-dubbo\dubbo-rpc\dubbo-rpc-dubbo\target\classes;E:\workstations\dubbo\incubator-dubbo\dubbo-rpc\dubbo-rpc-api\target\classes;E:\workstations\dubbo\incubator-dubbo\dubbo-remoting\dubbo-remoting-api\target\classes;E:\workstations\dubbo\incubator-dubbo\dubbo-container\dubbo-container-api\target\classes;E:\workstations\dubbo\incubator-dubbo\dubbo-remoting\dubbo-remoting-netty4\target\classes;C:\Users\wenchao.ren\.m2\repository\io\netty\netty-all\4.1.25.Final\netty-all-4.1.25.Final.jar;E:\workstations\dubbo\incubator-dubbo\dubbo-serialization\dubbo-serialization-hessian2\target\classes;E:\workstations\dubbo\incubator-dubbo\dubbo-serialization\dubbo-serialization-api\target\classes;C:\Users\wenchao.ren\.m2\repository\com\alibaba\fastjson\1.2.46\fastjson-1.2.46.jar;C:\Users\wenchao.ren\.m2\repository\com\esotericsoftware\kryo\4.0.1\kryo-4.0.1.jar;C:\Users\wenchao.ren\.m2\repository\com\esotericsoftware\reflectasm\1.11.3\reflectasm-1.11.3.jar;C:\Users\wenchao.ren\.m2\repository\org\ow2\asm\asm\5.0.4\asm-5.0.4.jar;C:\Users\wenchao.ren\.m2\repository\com\esotericsoftware\minlog\1.3.0\minlog-1.3.0.jar;C:\Users\wenchao.ren\.m2\repository\de\javakaffee\kryo-serializers\0.42\kryo-serializers-0.42.jar;C:\Users\wenchao.ren\.m2\repository\de\ruedigermoeller\fst\2.48-jdk-6\fst-2.48-jdk-6.jar;C:\Users\wenchao.ren\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.8.6\jackson-core-2.8.6.jar;C:\Users\wenchao.ren\.m2\repository\com\cedarsoftware\java-util\1.9.0\java-util-1.9.0.jar;C:\Users\wenchao.ren\.m2\repository\com\cedarsoftware\json-io\2.5.1\json-io-2.5.1.jar;C:\Users\wenchao.ren\.m2\repository\com\alibaba\hessian-lite\3.2.3\hessian-lite-3.2.3.jar;C:\Users\wenchao.ren\.m2\repository\org\objenesis\objenesis\2.6\objenesis-2.6.jar;C:\Users\wenchao.ren\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\182.3684.40\lib\idea_rt.jar;C:\Users\wenchao.ren\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\182.3684.40\lib\rt\debugger-agent.jar [20/08/1811:43:22:022 CST] main INFO zookeeper.ZooKeeper: Client environment:java.library.path=C:\Program Files\Java\jdk1.8.0_181\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files(x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files(x86)\NVIDIA Corporation\PhysX\Common;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Git\cmd;C:\Program Files\Microsoft VS Code\bin;C:\WINDOWS\System32\OpenSSH\;C:\Users\wenchao.ren\AppData\Local\Microsoft\WindowsApps;;. [20/08/1811:43:22:022 CST] main INFO zookeeper.ZooKeeper: Client environment:java.io.tmpdir=C:\Users\wenchao.ren\AppData\Local\Temp\ [20/08/1811:43:22:022 CST] main INFO zookeeper.ZooKeeper: Client environment:java.compiler=<NA> [20/08/1811:43:22:022 CST] main INFO zookeeper.ZooKeeper: Client environment:os.name=Windows 10 [20/08/1811:43:22:022 CST] main INFO zookeeper.ZooKeeper: Client environment:os.arch=amd64 [20/08/1811:43:22:022 CST] main INFO zookeeper.ZooKeeper: Client environment:os.version=10.0 [20/08/1811:43:22:022 CST] main INFO zookeeper.ZooKeeper: Client environment:user.name=wenchao.ren [20/08/1811:43:22:022 CST] main INFO zookeeper.ZooKeeper: Client environment:user.home=C:\Users\wenchao.ren [20/08/1811:43:22:022 CST] main INFO zookeeper.ZooKeeper: Client environment:user.dir=E:\workstations\dubbo\incubator-dubbo [20/08/1811:43:22:022 CST] main INFO zookeeper.ZooKeeper: Initiating client connection, connectString=localhost:2181 sessionTimeout=60000 watcher=org.apache.curator.ConnectionState@3dd69f5a [20/08/1811:43:22:022 CST] main-SendThread(127.0.0.1:2181) INFO zookeeper.ClientCnxn: Opening socket connection to server 127.0.0.1/127.0.0.1:2181. Will not attempt to authenticate using SASL(unknown error) [20/08/18 11:43:22:022 CST] main-SendThread(127.0.0.1:2181) INFO zookeeper.ClientCnxn: Socket connection established to 127.0.0.1/127.0.0.1:2181, initiating session [20/08/18 11:43:22:022 CST] main INFO zookeeper.ZookeeperRegistry: [DUBBO] Register: dubbo://192.168.116.1:20880/org.apache.dubbo.demo.DemoService?anyhost=true&application=demo-provider&dubbo=2.0.2&generic=false&interface=org.apache.dubbo.demo.DemoService&methods=sayHello&pid=6872&side=provider×tamp=1534779801013, dubbo version: , current host: 192.168.116.1 [20/08/18 11:43:22:022 CST] main-SendThread(127.0.0.1:2181) INFO zookeeper.ClientCnxn: Session establishment complete on server 127.0.0.1/127.0.0.1:2181, sessionid = 0x100001d37250002, negotiated timeout = 40000 [20/08/1811:43:22:022 CST] main-EventThread INFO state.ConnectionStateManager: State change: CONNECTED [20/08/1811:43:22:022 CST] main INFO zookeeper.ZookeeperRegistry: [DUBBO] Subscribe: provider://192.168.116.1:20880/org.apache.dubbo.demo.DemoService?anyhost=true&application=demo-provider&category=configurators&check=false&dubbo=2.0.2&generic=false&interface=org.apache.dubbo.demo.DemoService&methods=sayHello&pid=6872&side=provider×tamp=1534779801013, dubbo version: , current host: 192.168.116.1 [20/08/1811:43:22:022 CST] main INFO zookeeper.ZookeeperRegistry: [DUBBO] Notify urls for subscribe url provider://192.168.116.1:20880/org.apache.dubbo.demo.DemoService?anyhost=true&application=demo-provider&category=configurators&check=false&dubbo=2.0.2&generic=false&interface=org.apache.dubbo.demo.DemoService&methods=sayHello&pid=6872&side=provider×tamp=1534779801013, urls: [empty://192.168.116.1:20880/org.apache.dubbo.demo.DemoService?anyhost=true&application=demo-provider&category=configurators&check=false&dubbo=2.0.2&generic=false&interface=org.apache.dubbo.demo.DemoService&methods=sayHello&pid=6872&side=provider×tamp=1534779801013], dubbo version: , current host: 192.168.116.1
同时我们查看zk的话会发现:
1 2 3 4 5 6 7 8 9 10
[zk: localhost:2181(CONNECTED) 1] ls /dubbo [org.apache.dubbo.demo.DemoService] [zk: localhost:2181(CONNECTED) 2] ls /dubbo/org.apache.dubbo.demo.DemoService [configurators, providers] [zk: localhost:2181(CONNECTED) 3] [zk: localhost:2181(CONNECTED) 3] ls /dubbo/org.apache.dubbo.demo.DemoService/providers [dubbo%3A%2F%2F192.168.116.1%3A20880%2Forg.apache.dubbo.demo.DemoService%3Fanyhost%3Dtrue%26application%3Ddemo-provider%26dubbo%3D2.0.2%26generic%3Dfalse%26interface%3Dorg.apache.dubbo.demo.DemoService%26methods%3DsayHello%26pid%3D6872%26side%3Dprovider%26timestamp%3D1534779801013] [zk: localhost:2181(CONNECTED) 4] [zk: localhost:2181(CONNECTED) 4] ls /dubbo/org.apache.dubbo.demo.DemoService/configurators []
<!-- consumer's application name, used for tracing dependency relationship (not a matching criterion), don't set it same as provider --> <dubbo:applicationname="demo-consumer"/>
<!-- use multicast registry center to discover service --> <!--<dubbo:registry address="multicast://224.5.6.7:1234"/>--> <dubbo:registryprotocol="zookeeper"address="localhost:2181"/>
<!-- generate proxy for the remote service, then demoService can be used in the same way as the local regular interface --> <dubbo:referenceid="demoService"check="false"interface="org.apache.dubbo.demo.DemoService"/>
Connected to the target VM, address: '127.0.0.1:8434', transport: 'socket' [20/08/1811:49:40:040 CST] main INFO support.ClassPathXmlApplicationContext: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@551aa95a: startup date [Mon Aug 2023:49:40 CST 2018]; root of context hierarchy [20/08/18 11:49:40:040 CST] main INFO xml.XmlBeanDefinitionReader: Loading XML bean definitions from class path resource [META-INF/spring/dubbo-demo-consumer.xml] [20/08/1811:49:40:040 CST] main INFO logger.LoggerFactory: using logger: org.apache.dubbo.common.logger.log4j.Log4jLoggerAdapter [20/08/1811:49:41:041 CST] main WARN extension.SpringExtensionFactory: [DUBBO] No spring extension(bean) named:defaultCompiler, try to find an extension(bean) of type java.lang.String, dubbo version: , current host: 10.254.0.157 [20/08/18 11:49:41:041 CST] main WARN extension.SpringExtensionFactory: [DUBBO] No spring extension(bean) named:defaultCompiler, type:java.lang.String found, stop get bean., dubbo version: , current host: 10.254.0.157 [20/08/18 11:49:42:042 CST] main INFO imps.CuratorFrameworkImpl: Starting [20/08/18 11:49:42:042 CST] main INFO zookeeper.ZooKeeper: Client environment:zookeeper.version=3.4.9-1757313, built on 08/23/201606:50 GMT [20/08/1811:49:42:042 CST] main INFO zookeeper.ZooKeeper: Client environment:host.name=c [20/08/1811:49:42:042 CST] main INFO zookeeper.ZooKeeper: Client environment:java.version=1.8.0_181 [20/08/1811:49:42:042 CST] main INFO zookeeper.ZooKeeper: Client environment:java.vendor=Oracle Corporation [20/08/1811:49:42:042 CST] main INFO zookeeper.ZooKeeper: Client environment:java.home=C:\Program Files\Java\jdk1.8.0_181\jre [20/08/1811:49:42:042 CST] main INFO zookeeper.ZooKeeper: Client environment:java.class.path=C:\Program Files\Java\jdk1.8.0_181\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\rt.jar;E:\workstations\dubbo\incubator-dubbo\dubbo-demo\dubbo-demo-consumer\target\classes;E:\workstations\dubbo\incubator-dubbo\dubbo-demo\dubbo-demo-api\target\classes;E:\workstations\dubbo\incubator-dubbo\dubbo-config\dubbo-config-spring\target\classes;E:\workstations\dubbo\incubator-dubbo\dubbo-config\dubbo-config-api\target\classes;E:\workstations\dubbo\incubator-dubbo\dubbo-monitor\dubbo-monitor-api\target\classes;E:\workstations\dubbo\incubator-dubbo\dubbo-filter\dubbo-filter-validation\target\classes;C:\Users\wenchao.ren\.m2\repository\javax\validation\validation-api\1.1.0.Final\validation-api-1.1.0.Final.jar;E:\workstations\dubbo\incubator-dubbo\dubbo-filter\dubbo-filter-cache\target\classes;C:\Users\wenchao.ren\.m2\repository\javax\cache\cache-api\1.0.0\cache-api-1.0.0.jar;E:\workstations\dubbo\incubator-dubbo\dubbo-bootstrap\target\classes;E:\workstations\dubbo\incubator-dubbo\dubbo-common\target\classes;C:\Users\wenchao.ren\.m2\repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;C:\Users\wenchao.ren\.m2\repository\log4j\log4j\1.2.16\log4j-1.2.16.jar;C:\Users\wenchao.ren\.m2\repository\org\javassist\javassist\3.20.0-GA\javassist-3.20.0-GA.jar;C:\Users\wenchao.ren\.m2\repository\org\springframework\spring-beans\4.3.16.RELEASE\spring-beans-4.3.16.RELEASE.jar;C:\Users\wenchao.ren\.m2\repository\org\springframework\spring-core\4.3.16.RELEASE\spring-core-4.3.16.RELEASE.jar;C:\Users\wenchao.ren\.m2\repository\org\springframework\spring-web\4.3.16.RELEASE\spring-web-4.3.16.RELEASE.jar;C:\Users\wenchao.ren\.m2\repository\org\springframework\spring-aop\4.3.16.RELEASE\spring-aop-4.3.16.RELEASE.jar;C:\Users\wenchao.ren\.m2\repository\org\springframework\spring-context\4.3.16.RELEASE\spring-context-4.3.16.RELEASE.jar;C:\Users\wenchao.ren\.m2\repository\org\springframework\spring-expression\4.3.16.RELEASE\spring-expression-4.3.16.RELEASE.jar;E:\workstations\dubbo\incubator-dubbo\dubbo-rpc\dubbo-rpc-injvm\target\classes;E:\workstations\dubbo\incubator-dubbo\dubbo-registry\dubbo-registry-zookeeper\target\classes;E:\workstations\dubbo\incubator-dubbo\dubbo-registry\dubbo-registry-api\target\classes;E:\workstations\dubbo\incubator-dubbo\dubbo-cluster\target\classes;E:\workstations\dubbo\incubator-dubbo\dubbo-remoting\dubbo-remoting-zookeeper\target\classes;C:\Users\wenchao.ren\.m2\repository\org\apache\zookeeper\zookeeper\3.4.9\zookeeper-3.4.9.jar;C:\Users\wenchao.ren\.m2\repository\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;C:\Users\wenchao.ren\.m2\repository\org\slf4j\slf4j-log4j12\1.6.1\slf4j-log4j12-1.6.1.jar;C:\Users\wenchao.ren\.m2\repository\jline\jline\0.9.94\jline-0.9.94.jar;C:\Users\wenchao.ren\.m2\repository\io\netty\netty\3.10.5.Final\netty-3.10.5.Final.jar;C:\Users\wenchao.ren\.m2\repository\com\101tec\zkclient\0.2\zkclient-0.2.jar;C:\Users\wenchao.ren\.m2\repository\org\apache\curator\curator-framework\2.12.0\curator-framework-2.12.0.jar;C:\Users\wenchao.ren\.m2\repository\org\apache\curator\curator-client\2.12.0\curator-client-2.12.0.jar;C:\Users\wenchao.ren\.m2\repository\com\google\guava\guava\16.0.1\guava-16.0.1.jar;E:\workstations\dubbo\incubator-dubbo\dubbo-registry\dubbo-registry-multicast\target\classes;E:\workstations\dubbo\incubator-dubbo\dubbo-rpc\dubbo-rpc-dubbo\target\classes;E:\workstations\dubbo\incubator-dubbo\dubbo-rpc\dubbo-rpc-api\target\classes;E:\workstations\dubbo\incubator-dubbo\dubbo-remoting\dubbo-remoting-api\target\classes;E:\workstations\dubbo\incubator-dubbo\dubbo-container\dubbo-container-api\target\classes;E:\workstations\dubbo\incubator-dubbo\dubbo-remoting\dubbo-remoting-netty4\target\classes;C:\Users\wenchao.ren\.m2\repository\io\netty\netty-all\4.1.25.Final\netty-all-4.1.25.Final.jar;E:\workstations\dubbo\incubator-dubbo\dubbo-serialization\dubbo-serialization-hessian2\target\classes;E:\workstations\dubbo\incubator-dubbo\dubbo-serialization\dubbo-serialization-api\target\classes;C:\Users\wenchao.ren\.m2\repository\com\alibaba\fastjson\1.2.46\fastjson-1.2.46.jar;C:\Users\wenchao.ren\.m2\repository\com\esotericsoftware\kryo\4.0.1\kryo-4.0.1.jar;C:\Users\wenchao.ren\.m2\repository\com\esotericsoftware\reflectasm\1.11.3\reflectasm-1.11.3.jar;C:\Users\wenchao.ren\.m2\repository\org\ow2\asm\asm\5.0.4\asm-5.0.4.jar;C:\Users\wenchao.ren\.m2\repository\com\esotericsoftware\minlog\1.3.0\minlog-1.3.0.jar;C:\Users\wenchao.ren\.m2\repository\de\javakaffee\kryo-serializers\0.42\kryo-serializers-0.42.jar;C:\Users\wenchao.ren\.m2\repository\de\ruedigermoeller\fst\2.48-jdk-6\fst-2.48-jdk-6.jar;C:\Users\wenchao.ren\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.8.6\jackson-core-2.8.6.jar;C:\Users\wenchao.ren\.m2\repository\com\cedarsoftware\java-util\1.9.0\java-util-1.9.0.jar;C:\Users\wenchao.ren\.m2\repository\com\cedarsoftware\json-io\2.5.1\json-io-2.5.1.jar;C:\Users\wenchao.ren\.m2\repository\com\alibaba\hessian-lite\3.2.3\hessian-lite-3.2.3.jar;C:\Users\wenchao.ren\.m2\repository\org\objenesis\objenesis\2.6\objenesis-2.6.jar;C:\Users\wenchao.ren\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\182.3684.40\lib\idea_rt.jar;C:\Users\wenchao.ren\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\182.3684.40\lib\rt\debugger-agent.jar [20/08/1811:49:42:042 CST] main INFO zookeeper.ZooKeeper: Client environment:java.library.path=C:\Program Files\Java\jdk1.8.0_181\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files(x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files(x86)\NVIDIA Corporation\PhysX\Common;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Git\cmd;C:\Program Files\Microsoft VS Code\bin;C:\WINDOWS\System32\OpenSSH\;C:\Users\wenchao.ren\AppData\Local\Microsoft\WindowsApps;;. [20/08/1811:49:42:042 CST] main INFO zookeeper.ZooKeeper: Client environment:java.io.tmpdir=C:\Users\wenchao.ren\AppData\Local\Temp\ [20/08/1811:49:42:042 CST] main INFO zookeeper.ZooKeeper: Client environment:java.compiler=<NA> [20/08/1811:49:42:042 CST] main INFO zookeeper.ZooKeeper: Client environment:os.name=Windows 10 [20/08/1811:49:42:042 CST] main INFO zookeeper.ZooKeeper: Client environment:os.arch=amd64 [20/08/1811:49:42:042 CST] main INFO zookeeper.ZooKeeper: Client environment:os.version=10.0 [20/08/1811:49:42:042 CST] main INFO zookeeper.ZooKeeper: Client environment:user.name=wenchao.ren [20/08/1811:49:42:042 CST] main INFO zookeeper.ZooKeeper: Client environment:user.home=C:\Users\wenchao.ren [20/08/1811:49:42:042 CST] main INFO zookeeper.ZooKeeper: Client environment:user.dir=E:\workstations\dubbo\incubator-dubbo [20/08/1811:49:42:042 CST] main INFO zookeeper.ZooKeeper: Initiating client connection, connectString=localhost:2181 sessionTimeout=60000 watcher=org.apache.curator.ConnectionState@59b38691 [20/08/1811:49:42:042 CST] main-SendThread(0:0:0:0:0:0:0:1:2181) INFO zookeeper.ClientCnxn: Opening socket connection to server 0:0:0:0:0:0:0:1/0:0:0:0:0:0:0:1:2181. Will not attempt to authenticate using SASL(unknown error) [20/08/18 11:49:42:042 CST] main-SendThread(0:0:0:0:0:0:0:1:2181) INFO zookeeper.ClientCnxn: Socket connection established to 0:0:0:0:0:0:0:1/0:0:0:0:0:0:0:1:2181, initiating session [20/08/18 11:49:42:042 CST] main-SendThread(0:0:0:0:0:0:0:1:2181) INFO zookeeper.ClientCnxn: Session establishment complete on server 0:0:0:0:0:0:0:1/0:0:0:0:0:0:0:1:2181, sessionid = 0x100001d37250004, negotiated timeout = 40000 [20/08/1811:49:42:042 CST] main-EventThread INFO state.ConnectionStateManager: State change: CONNECTED [20/08/1811:49:42:042 CST] main INFO zookeeper.ZookeeperRegistry: [DUBBO] Register: consumer://10.254.0.157/org.apache.dubbo.demo.DemoService?application=demo-consumer&category=consumers&check=false&dubbo=2.0.2&interface=org.apache.dubbo.demo.DemoService&methods=sayHello&pid=2720&qos.port=33333&side=consumer×tamp=1534780181816, dubbo version: , current host: 10.254.0.157 [20/08/1811:49:42:042 CST] main INFO zookeeper.ZookeeperRegistry: [DUBBO] Subscribe: consumer://10.254.0.157/org.apache.dubbo.demo.DemoService?application=demo-consumer&category=providers,configurators,routers&check=false&dubbo=2.0.2&interface=org.apache.dubbo.demo.DemoService&methods=sayHello&pid=2720&qos.port=33333&side=consumer×tamp=1534780181816, dubbo version: , current host: 10.254.0.157 [20/08/1811:49:42:042 CST] main INFO zookeeper.ZookeeperRegistry: [DUBBO] Notify urls for subscribe url consumer://10.254.0.157/org.apache.dubbo.demo.DemoService?application=demo-consumer&category=providers,configurators,routers&check=false&dubbo=2.0.2&interface=org.apache.dubbo.demo.DemoService&methods=sayHello&pid=2720&qos.port=33333&side=consumer×tamp=1534780181816, urls: [dubbo://192.168.116.1:20880/org.apache.dubbo.demo.DemoService?anyhost=true&application=demo-provider&dubbo=2.0.2&generic=false&interface=org.apache.dubbo.demo.DemoService&methods=sayHello&pid=6872&side=provider×tamp=1534779801013, empty://10.254.0.157/org.apache.dubbo.demo.DemoService?application=demo-consumer&category=configurators&check=false&dubbo=2.0.2&interface=org.apache.dubbo.demo.DemoService&methods=sayHello&pid=2720&qos.port=33333&side=consumer×tamp=1534780181816, empty://10.254.0.157/org.apache.dubbo.demo.DemoService?application=demo-consumer&category=routers&check=false&dubbo=2.0.2&interface=org.apache.dubbo.demo.DemoService&methods=sayHello&pid=2720&qos.port=33333&side=consumer×tamp=1534780181816], dubbo version: , current host: 10.254.0.157 [20/08/1811:49:43:043 CST] main INFO transport.AbstractClient: [DUBBO] Successed connect to server /192.168.116.1:20880 from NettyClient 10.254.0.157 using dubbo version , channel is NettyChannel [channel=[id: 0x5a2b2c61, L:/192.168.116.1:8464 - R:/192.168.116.1:20880]], dubbo version: , current host: 10.254.0.157 [20/08/1811:49:43:043 CST] main INFO transport.AbstractClient: [DUBBO] Start NettyClient c/10.254.0.157 connect to the server /192.168.116.1:20880, dubbo version: , current host: 10.254.0.157 [20/08/1811:49:43:043 CST] main INFO config.AbstractConfig: [DUBBO] Refer dubbo service org.apache.dubbo.demo.DemoService from url zookeeper://localhost:2181/org.apache.dubbo.registry.RegistryService?anyhost=true&application=demo-consumer&check=false&dubbo=2.0.2&generic=false&interface=org.apache.dubbo.demo.DemoService&methods=sayHello&pid=2720&qos.port=33333®ister.ip=10.254.0.157&remote.timestamp=1534779801013&side=consumer×tamp=1534780181816, dubbo version: , current host: 10.254.0.157 Hello world, response from provider: 192.168.116.1:20880 Hello world, response from provider: 192.168.116.1:20880 Hello world, response from provider: 192.168.116.1:20880
此时我们看zk节点:
1 2 3 4 5 6 7 8 9 10 11
[zk: localhost:2181(CONNECTED) 7] ls /dubbo/org.apache.dubbo.demo.DemoService [consumers, configurators, routers, providers] [zk: localhost:2181(CONNECTED) 8] ls /dubbo/org.apache.dubbo.demo.DemoService/consumers [consumer%3A%2F%2F10.254.0.157%2Forg.apache.dubbo.demo.DemoService%3Fapplication%3Ddemo-consumer%26category%3Dconsumers%26check%3Dfalse%26dubbo%3D2.0.2%26interface%3Dorg.apache.dubbo.demo.DemoService%26methods%3DsayHello%26pid%3D2720%26qos.port%3D33333%26side%3Dconsumer%26timestamp%3D1534780181816] [zk: localhost:2181(CONNECTED) 9] ls /dubbo/org.apache.dubbo.demo.DemoService/configurators [] [zk: localhost:2181(CONNECTED) 10] ls /dubbo/org.apache.dubbo.demo.DemoService/routers [] [zk: localhost:2181(CONNECTED) 11] ls /dubbo/org.apache.dubbo.demo.DemoService/providers [dubbo%3A%2F%2F192.168.116.1%3A20880%2Forg.apache.dubbo.demo.DemoService%3Fanyhost%3Dtrue%26application%3Ddemo-provider%26dubbo%3D2.0.2%26generic%3Dfalse%26interface%3Dorg.apache.dubbo.demo.DemoService%26methods%3DsayHello%26pid%3D6872%26side%3Dprovider%26timestamp%3D1534779801013] [zk: localhost:2181(CONNECTED) 12]
可以看到多了consumer和routers节点。
同时consumer端不断输出Hello world, response from provider: 192.168.116.1:20880的日志,说明我们的环境以及搭建完成了。
2019-01-21 16:55:58,675 WARN wtraceId[] wtracer[] [org.springframework.kafka.KafkaListenerEndpointContainer#0-0-C-1] c.w.f.w.k.LogConsumerConfiguration:45 - [wcollect]batch pull data from kafka error java.lang.IllegalStateException: No entry found for connection 30 at org.apache.kafka.clients.ClusterConnectionStates.nodeState(ClusterConnectionStates.java:330) at org.apache.kafka.clients.ClusterConnectionStates.disconnected(ClusterConnectionStates.java:134) at org.apache.kafka.clients.NetworkClient.initiateConnect(NetworkClient.java:921) at org.apache.kafka.clients.NetworkClient.ready(NetworkClient.java:287) at org.apache.kafka.clients.consumer.internals.ConsumerNetworkClient.trySend(ConsumerNetworkClient.java:474) at org.apache.kafka.clients.consumer.internals.ConsumerNetworkClient.poll(ConsumerNetworkClient.java:255) at org.apache.kafka.clients.consumer.internals.ConsumerNetworkClient.poll(ConsumerNetworkClient.java:236) at org.apache.kafka.clients.consumer.KafkaConsumer.pollForFetches(KafkaConsumer.java:1243) at org.apache.kafka.clients.consumer.KafkaConsumer.poll(KafkaConsumer.java:1188) at org.apache.kafka.clients.consumer.KafkaConsumer.poll(KafkaConsumer.java:1164) at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.run(KafkaMessageListenerContainer.java:728) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266) at java.util.concurrent.FutureTask.run(FutureTask.java) at java.lang.Thread.run(Thread.java:748)
############################# Socket Server Settings #############################
# The address the socket server listens on. It will get the value returned from # java.net.InetAddress.getCanonicalHostName() if not configured. # FORMAT: # listeners = listener_name://host_name:port # EXAMPLE: # listeners = PLAINTEXT://your.host.name:9092 listeners=PLAINTEXT://xxx.xx.xxx.xxx.xxx.com:9092 advertised.listeners=PLAINTEXT://xxx.xxx.xxx.xxx:9092
因此导致我连接不上kafka的broker。解决办法也很简单,使用
因此我们需要研究一下这几个参数的作用
listeners
官网的解释如下:
Listener List - Comma-separated list of URIs we will listen on and their protocols. Specify hostname as 0.0.0.0 to bind to all interfaces. Leave hostname empty to bind to default interface. Examples of legal listener lists: PLAINTEXT://myhost:9092,TRACE://:9091 PLAINTEXT://0.0.0.0:9092, TRACE://localhost:9093
DEPRECATED: only used when listeners is not set. Use listeners instead. hostname of broker. If this is set, it will only bind to this address. If this is not set, it will bind to all interfaces
string类型,默认值为""
advertised.listeners
Listeners to publish to ZooKeeper for clients to use, if different than the listeners above. In IaaS environments, this may need to be different from the interface to which the broker binds. If this is not set, the value for listeners will be used.
string类型,默认值为null
advertised.port
DEPRECATED: only used when advertised.listeners or listeners are not set. Use advertised.listeners instead. The port to publish to ZooKeeper for clients to use. In IaaS environments, this may need to be different from the port to which the broker binds. If this is not set, it will publish the same port that the broker binds to.
DEPRECATED: only used when advertised.listeners or listeners are not set. Use advertised.listeners instead. Hostname to publish to ZooKeeper for clients to use. In IaaS environments, this may need to be different from the interface to which the broker binds. If this is not set, it will use the value for host.name if configured. Otherwise it will use the value returned from java.net.InetAddress.getCanonicalHostName().