zoukankan      html  css  js  c++  java
  • 6.nuget安装C#Driver驱动ZooKeeperNet

    一: C# 的Drivers
     
      1. nuget上下载 zookeeper.Net
      
     
      IWatcher是什么?:
        client 连接到 server 后,会在server上面注册一个watcher[handler]
        如果server connection完成之后,反向通知client。(sendresponse)
        client会收到这个 handler
        client会利用这个handler找到这个注册的watcher,执行回调函数
         
     IWatcher接口的实现
        public class ZookeeperWatcher : IWatcher
        {
            public static CountdownEvent countdownEvent = new CountdownEvent(1);
            public void Process(WatchedEvent @event)
            {
                Console.WriteLine("path={0},state={1},type={2}", @event.Path, @event.State, @event.Type);
                countdownEvent.Signal(); 
            }
        }
        可以把IWatcher理解成一个 Observer 观察者,注册到 zookeeper中
     
        zookeeper初始化是一个异步的过程。
         【sendthread,eventthread】
           sendthread =》 zookeeper server
           eventthread =》 专门处理server返回的watcher通知
     
      2. Refletor 反编译DLL
     
      3. 【长连接 + watcher 模式】
        心跳: timeout/3
     
      4. 配置log4net.config
      注册:
      
      log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(AppDomain.CurrentDomain.BaseDirectory + "log4net.config"));
               
      使用:
      private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
     
      5. 客户端和server交互(心跳检测)
        client < = > server 【返回sessionid】
        syncConnect 同步成功 【网络正常】
        disconnect 失去连接等待重连 【网络断线】
        expired 断网后重连, Server会返回session过期 (一直保持重连,知道网络正常)
     
        为什么重连后,server会把sessionid抹掉?
          【临时节点概念,当网络断线后,datamip会被清空】
          你的当前zkCli.sh节点是属于那个sessionid的
     
     
      6. zookeeper连接初始化指定根路径
        连接到自己需要的路径。
         
      ZooKeeperNet.ZooKeeper zookeeper = new ZooKeeperNet.ZooKeeper("192.168.1.120:2181/datamip",
                    TimeSpan.FromSeconds(5),
                    new ZookeeperWatcher());
    
                //通过wait函数,等待ZookeeperWatcher 回调函数执行成功
                ZookeeperWatcher.countdownEvent.Wait();
                var list = zookeeper.GetChildren("/", false);
     
     
     
     
     
     
     
     
     
     
  • 相关阅读:
    ZedGrapy使用实例
    C#分割字符串(包括使用字符串分割)
    从VS2005项目转换为VS2008项目(C#版)
    关于SQL操作的一些经验
    android socket 编程总结
    Excel绘制人口金字塔图
    使用命令让IE全屏显示指定的页面,适用于触摸屏终端机
    毕业这两年
    使用XML数据结合XSLT导出Excel
    XSLT实现XML作为数据源在web页面显示人口金字塔统计图
  • 原文地址:https://www.cnblogs.com/dragon-L/p/8563382.html
Copyright © 2011-2022 走看看