ZooKeeper服務發現客戶端--重連認證
前文:
http://blog.itpub.net/29254281/viewspace-2108223/
挖坑小王子
這裡面有大坑.
由於線上都配置了ACL控制
前文的程式碼,在Reconnection的時候,會有如下異常.
2016-06-23 22:13:01 [ main-EventThread:23807640 ] - [ INFO ] State change: RECONNECTED
2016-06-23 22:13:01 [ ConnectionStateManager-0:23807641 ] - [ INFO ] zk connection state changed:RECONNECTED
2016-06-23 22:13:02 [ pool-1-thread-1:23807734 ] - [ ERROR ] KeeperErrorCode = NoAuth for /service
org.apache.zookeeper.KeeperException$NoAuthException: KeeperErrorCode = NoAuth for /service
at org.apache.zookeeper.KeeperException.create(KeeperException.java:113)
at org.apache.zookeeper.KeeperException.create(KeeperException.java:51)
at org.apache.zookeeper.ZooKeeper.create(ZooKeeper.java:783)
at org.apache.curator.framework.imps.CreateBuilderImpl$11.call(CreateBuilderImpl.java:676)
at org.apache.curator.framework.imps.CreateBuilderImpl$11.call(CreateBuilderImpl.java:660)
at org.apache.curator.RetryLoop.callWithRetry(RetryLoop.java:107)
at org.apache.curator.framework.imps.CreateBuilderImpl.pathInForeground(CreateBuilderImpl.java:657)
at org.apache.curator.framework.imps.CreateBuilderImpl.protectedPathInForeground(CreateBuilderImpl.java:441)
at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:431)
at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:44)
at com.vv.zkClient.ServiceProvider.run(ServiceProvider.java:69)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
這是因為重連的時候,沒有認證資訊.
修改connection函式即可.
http://blog.itpub.net/29254281/viewspace-2108223/
挖坑小王子
這裡面有大坑.
由於線上都配置了ACL控制
前文的程式碼,在Reconnection的時候,會有如下異常.
2016-06-23 22:13:01 [ main-EventThread:23807640 ] - [ INFO ] State change: RECONNECTED
2016-06-23 22:13:01 [ ConnectionStateManager-0:23807641 ] - [ INFO ] zk connection state changed:RECONNECTED
2016-06-23 22:13:02 [ pool-1-thread-1:23807734 ] - [ ERROR ] KeeperErrorCode = NoAuth for /service
org.apache.zookeeper.KeeperException$NoAuthException: KeeperErrorCode = NoAuth for /service
at org.apache.zookeeper.KeeperException.create(KeeperException.java:113)
at org.apache.zookeeper.KeeperException.create(KeeperException.java:51)
at org.apache.zookeeper.ZooKeeper.create(ZooKeeper.java:783)
at org.apache.curator.framework.imps.CreateBuilderImpl$11.call(CreateBuilderImpl.java:676)
at org.apache.curator.framework.imps.CreateBuilderImpl$11.call(CreateBuilderImpl.java:660)
at org.apache.curator.RetryLoop.callWithRetry(RetryLoop.java:107)
at org.apache.curator.framework.imps.CreateBuilderImpl.pathInForeground(CreateBuilderImpl.java:657)
at org.apache.curator.framework.imps.CreateBuilderImpl.protectedPathInForeground(CreateBuilderImpl.java:441)
at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:431)
at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:44)
at com.vv.zkClient.ServiceProvider.run(ServiceProvider.java:69)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
這是因為重連的時候,沒有認證資訊.
修改connection函式即可.
- private void connection() {
- try {
- this.client = CuratorFrameworkFactory.newClient(meta.getConnectionString(),
- new RetryUntilElapsed(Integer.MAX_VALUE, 1000));
- client.getConnectionStateListenable().addListener(new ConnectionStateListener(){
- public void stateChanged(CuratorFramework arg0,
- ConnectionState arg1) {
- LOGGER.info("zk client connection state changed:" + arg1.toString());
- if("RECONNECTED".equals(arg1.toString())){
- try {
- arg0.getZookeeperClient().getZooKeeper().addAuthInfo("digest", meta.getReadwritePassword().getBytes());
- } catch (Exception e) {
- LOGGER.error(e.getMessage(),e);
- }
- }
- }
- });
- client.start();
- client.getZookeeperClient().getZooKeeper().addAuthInfo("digest", meta.getReadOnlyPassword().getBytes());
- } catch (Exception e) {
- LOGGER.error(e.getMessage(), e);
- }
- }
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29254281/viewspace-2121214/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Go基於gRPC實現客戶端連入服務端GoRPC客戶端服務端
- Kubernetes客戶端認證(三)—— Kubernetes使用CertificateSigningRequest方式簽發客戶端證書客戶端
- 服務端,客戶端服務端客戶端
- 客戶端,服務端客戶端服務端
- iOS逆向-客戶端認證iOS客戶端
- 【zookeeper之七】Zookeeper客戶端客戶端
- 【Zookeeper】zookeeper客戶端KeeperErrorCode = ConnectionLoss客戶端Error
- Zookeeper 客戶端 API客戶端API
- golang實現tcp客戶端服務端程式GolangTCP客戶端服務端
- socket實現服務端多執行緒,客戶端重複輸入服務端執行緒客戶端
- ASP.NET Core2利用Jwt技術在服務端實現對客戶端的身份認證ASP.NETJWT服務端客戶端
- SharePoint Online 認證Net客戶端物件客戶端物件
- 基於CFSSL工具建立CA證書,服務端證書,客戶端證書服務端客戶端
- ZooKeeper客戶端CRUD命令客戶端
- Zookeeper Java 客戶端搭建Java客戶端
- java netty 實現 websocket 服務端和客戶端雙向通訊 實現心跳和斷線重連 完整示例JavaNettyWeb服務端客戶端
- Kubernetes客戶端認證(二)—— 基於ServiceAccount的JWTToken認證客戶端JWT
- 實現客戶端與服務端的HTTP通訊客戶端服務端HTTP
- 服務端渲染和客戶端渲染服務端客戶端
- 服務端c100k連線測試和客戶端65535測試驗證2服務端客戶端
- Https雙向認證Android客戶端配置HTTPAndroid客戶端
- zookeeper的Java客戶端APIJava客戶端API
- Qt實現網路聊天室(客戶端,服務端)QT客戶端服務端
- Kubernetes客戶端認證——基於CA證書的雙向認證方式客戶端
- netty服務端監聽客戶端連線加入和斷開事件Netty服務端客戶端事件
- TCP協議服務端和客戶端的連線與通訊TCP協議服務端客戶端
- python建立tcp服務端和客戶端PythonTCP服務端客戶端
- go-自籤ca證書,客戶端數字證書,服務端數字證書Go客戶端服務端
- Java服務端和客戶端開發輔助工具UtilsJava服務端客戶端
- 從客戶端向服務端發起請求(3種)客戶端服務端
- Zookeeper C客戶端庫編譯客戶端編譯
- Java的oauth2.0 服務端與客戶端的實現JavaOAuth服務端客戶端
- OSSEC服務端配置客戶端批次部署方案服務端客戶端
- TCP程式設計之服務端和客戶端的開發TCP程式設計服務端客戶端
- 客戶現場服務規範
- Zookeeper實現服務註冊/發現
- Spring Boot 整合 WebSocket 實現服務端推送訊息到客戶端Spring BootWeb服務端客戶端
- HTML轉PDF的純客戶端和純服務端實現方案HTML客戶端服務端
- php原生socket實現客戶端與服務端資料傳輸PHP客戶端服務端