2012-04-05 10 views
2

我正在使用Zookeeper v3.3.3 + dfsg2-1ubuntu1,在ubuntu vm上运行。 (虚拟机与NAT网络连接运行)无法从C#应用程序使用Apache .NET库连接到ZooKeeper

在我的机器(Windows 7)中,如果我跑:zkCli.cmd -server 10.10.135.19:2181它连接正常,我可以执行create S,get小号等

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

我使用它以下列方式:

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(); 
    } 

的问题是,这只是挂起。在动物园管理员日志,我看到以下内容:

2012-04-05 08:12:21,376 - INFO [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:[email protected]] - 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:[email protected]] - Client attempting to establish new session at /10.0.2.2:51057 
2012-04-05 08:12:21,383 - INFO [SyncThread:0:[email protected]] - 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:[email protected]] - 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:[email protected]] - Client attempting to establish new session at /10.0.2.2:51059 
2012-04-05 08:12:22,505 - INFO [SyncThread:0:[email protected]] - Established session 0x1367c91bf580048 with negotiated timeout 4000 for client /10.0.2.2:51059 
2012-04-05 08:12:26,000 - INFO [SessionTracker:[email protected]] - Expiring session 0x1367c91bf580047, timeout of 4000ms exceeded 
2012-04-05 08:12:26,001 - INFO [ProcessThread:-1:[email protected]] - Processed session termination for sessionid: 0x1367c91bf580047 
2012-04-05 08:12:26,004 - INFO [SyncThread:0:[email protected]] - Closed socket connection for client /10.0.2.2:51057 which had sessionid 0x1367c91bf580047 
2012-04-05 08:12:28,001 - INFO [SessionTracker:[email protected]] - Expiring session 0x1367c91bf580048, timeout of 4000ms exceeded 
2012-04-05 08:12:28,002 - INFO [ProcessThread:-1:[email protected]] - Processed session termination for sessionid: 0x1367c91bf580048 
2012-04-05 08:12:28,004 - INFO [SyncThread:0:[email protected]] - Closed socket connection for client /10.0.2.2:51059 which had sessionid 0x1367c91bf580048 

,这样下去,直到我手动杀进程,即WaitUntilConnected()方法永远不会返回。 (通过调试验证)

看起来好像客户端连接到达服务器正常,但Watcher从未意识到这一点,在该通道上没有进一步的事情发生,并且服务器终止连接,仅为客户端重试。任何想法我在这里做错了吗?

+0

是watcher.Process曾被称为? – miniBill 2012-04-30 10:00:38

+0

没有。我已经通过一些源代码。在内部,连接状态永远不会超过CONNECTING状态,因为当它试图从ZK服务器读取套接字上的第一个响应时,它什么都没有发现。 – 2012-04-30 12:10:30

+0

您可以尝试使用诸如wireshark之​​类的工具来查看客户端和代码连接之间的不同之处。 – miniBill 2012-04-30 12:27:38

回答

5

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

  • 通过从github获取源代码来构建源代码。确保获得et-develop分支。
  • 在顶层(这将调用jute,其产生在C#项目中使用RPC类)
  • 在那里打开的src/dotnet文件夹,并将该溶液和
  • 构建它

我运行ant运行了与本地ZooKeeper连接的单元测试,并且运行良好。

+1

https://github.com/ExactTargetDev/zookeeper/network – Henrik 2014-01-04 17:44:40

相关问题