3

我正在使用 Zookeeper v3.3.3+dfsg2-1ubuntu1,在 ubuntu vm 上运行。(VM 正在使用 NAT 网络连接运行)

在我的开发机器(Windows 7)上,如果我运行:zkCli.cmd -server 10.10.135.19:2181它连接良好,我可以执行creates、gets 等。

我有一个 C# 4 应用程序,它具有对 Org.Apache.ZooKeeper v1.0.0.0 的 NuGet 依赖项。

我通过以下方式使用它:

  class watcher : IWatcher
  {
     private readonly ManualResetEventSlim _connected = new ManualResetEventSlim(false);
     private WatchedEvent _event;

     public void WaitUntilConnected()
     {
        _connected.Wait();

        if (_event == null) throw new ApplicationException("bad state");
        if (_event.State != KeeperState.SyncConnected)
           throw new ApplicationException("cannot connect");
     }

     public void Process(WatchedEvent @event)
     {
        _event = @event;
        _connected.Set();
     }
  }

  ...

  public void TestZooKeeper()
  {
     _countdownWatcher = new watcher();
     _zk = new ZooKeeper(
        Settings.Default.ZookeeperConnectionString, // 10.10.135.19:2181
        new TimeSpan(Settings.Default.ZookeeperConnectionTimeout), // 10000
        _countdownWatcher);
     _countdownWatcher.WaitUntilConnected();
  }

问题是这只是挂起。在 zookeeper 日志中,我看到以下内容:

2012-04-05 08:12:21,376 - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn$Factory@251] - Accepted socket         connection from /10.0.2.2:51057
2012-04-05 08:12:21,379 - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@777] - Client attempting to establish new session at /10.0.2.2:51057
2012-04-05 08:12:21,383 - INFO  [SyncThread:0:NIOServerCnxn@1580] - Established session 0x1367c91bf580047 with negotiated timeout 4000 for client /10.0.2.2:51057
2012-04-05 08:12:22,500 - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn$Factory@251] - Accepted socket connection from /10.0.2.2:51059
2012-04-05 08:12:22,502 - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@777] - Client attempting to establish new session at /10.0.2.2:51059
2012-04-05 08:12:22,505 - INFO  [SyncThread:0:NIOServerCnxn@1580] - Established session 0x1367c91bf580048 with negotiated timeout 4000 for client /10.0.2.2:51059
2012-04-05 08:12:26,000 - INFO  [SessionTracker:ZooKeeperServer@314] - Expiring session 0x1367c91bf580047, timeout of 4000ms exceeded
2012-04-05 08:12:26,001 - INFO  [ProcessThread:-1:PrepRequestProcessor@387] - Processed session termination for sessionid: 0x1367c91bf580047
2012-04-05 08:12:26,004 - INFO  [SyncThread:0:NIOServerCnxn@1435] - Closed socket connection for client /10.0.2.2:51057 which had sessionid 0x1367c91bf580047
2012-04-05 08:12:28,001 - INFO  [SessionTracker:ZooKeeperServer@314] - Expiring session 0x1367c91bf580048, timeout of 4000ms exceeded
2012-04-05 08:12:28,002 - INFO  [ProcessThread:-1:PrepRequestProcessor@387] - Processed session termination for sessionid: 0x1367c91bf580048
2012-04-05 08:12:28,004 - INFO  [SyncThread:0:NIOServerCnxn@1435] - Closed socket connection for client /10.0.2.2:51059 which had sessionid 0x1367c91bf580048

这种情况一直持续到我手动终止该过程,即该WaitUntilConnected()方法永远不会返回。(通过调试验证)

似乎客户端连接可以很好地到达服务器,但观察者从未意识到这一点,该通道上没有进一步发生,服务器终止连接,只是让客户端重试。有什么想法我在这里做错了吗?

4

1 回答 1

6

事实证明,ZooKeeper 的 C# 客户端库的规范版本位于https://github.com/ExactTargetDev/zookeeper/tree/et-develop,这与 ZooKeeper wiki 指向的不同。

  • 通过从 github 获取源来构建源。确保获得et-develop分支。
  • ant在顶层运行(这会调用jute,它会生成 C# 项目中使用的 RPC 类)
  • 打开src/dotnet文件夹和其中的解决方案,然后
  • 建造它

我运行了与本地 ZooKeeper 连接的单元测试,它们运行良好。

于 2012-05-03T08:26:43.297 回答