gpt4 book ai didi

c# - 无法使用 apache .NET 库从 C# 应用程序连接到 ZooKeeper

转载 作者:行者123 更新时间:2023-12-05 01:48:35 28 4
gpt4 key购买 nike

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

在我的开发机器 (windows 7) 上,如果我运行:zkCli.cmd -server 10.10.135.19:2181 它连接正常,我可以执行 createget

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

我正在按以下方式使用它:

  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: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() 方法永远不会返回。 (通过调试验证)

似乎客户端连接可以正常到达服务器,但观察者从未意识到这一点,该 channel 上没有进一步发生,服务器终止连接,只为客户端重试。知道我在这里做错了什么吗?

最佳答案

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

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

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

关于c# - 无法使用 apache .NET 库从 C# 应用程序连接到 ZooKeeper,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10023539/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com