Closed radduri closed 8 years ago
Can you please provide more information? a code sample will be much appreciated. Thanks.
Please find the code below. I am calling the ZooKeeperClient like the below
var data = new ZooKeeperClinet(_zookeperIps, "Company").GetData();
ZooKeeperClient Code
`using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using org.apache.zookeeper;
namespace Ipreo.Services.SolrService.Repository { public class ZooKeeperClinet { private readonly string _nodePath; public ZooKeeperClinet(string hostPort, string nodePath) {
_zk = new ZooKeeper(hostPort, ConnectionTimeOut, NullWatcher.Instance);
while (_zk.getState() != ZooKeeper.States.CONNECTED)
{
Task.Delay(5000).ConfigureAwait(false);
}
_nodePath = nodePath;
_mCurrentRoot = CreateNode(hostPort, "/" + nodePath, CreateMode.PERSISTENT_SEQUENTIAL).Result;
}
protected const int ConnectionTimeOut = 400000;
private string _mCurrentRoot;
private readonly ZooKeeper _zk;
public DataResult GetData()
{
var data = _zk.getDataAsync("/"+ _nodePath, false).Result;
var stat = data.Stat;
return data;
}
protected async Task<string> CreateNode(string hostPort, string path, CreateMode createMode)
{
var newNode = await _zk.createAsync(path, Encoding.UTF8.GetBytes(path), ZooDefs.Ids.OPEN_ACL_UNSAFE, createMode);
await _zk.sync("/");
return newNode;
}
protected class NullWatcher : Watcher
{
public static readonly NullWatcher Instance = new NullWatcher();
private NullWatcher() { }
public override Task process(WatchedEvent @event)
{
return Task.Delay(0);
// nada
}
}
}
} `
In GetData method I am getting that error. Please find the stacks trace
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at Ipreo.Services.SolrService.Repository.ZooKeeperClinet.GetData()
at Ipreo.Services.SolrService.Repository.Repository.
There's a bug in your code. Replace the following
var data = _zk.getDataAsync("/"+ _nodePath, false).Result;
with
var data = _zk.getDataAsync(_mCurrentRoot, false).Result;
Thanks for your response. I have done that change but now. the response i am getting is the nodePath string only.
Am I doing any thing wrong?
Regards, Ram
@radduri , can you please elaborate on what you're trying to accomplish ?
@shayhatsor, Seems I am able to get the data from Solr but getting an issue after i moved it to DEV server.
My DEV server has a proxy enabled so request is blocking. Can you please help, how to use proxy with this component.
Regards, Ram
I personally have never used the ZooKeeper client (mine or the java version) with a proxy server. But I think I can provide some insight. The ZK client maintains an open TCP connection to one of the ZK servers (default port is 2181, configurable) of a ZK cluster. So if you configure the proxy server to tunnel TCP connections (e.g. incoming port 2181) to one of the ZK servers, it should work.
@radduri, were you able to resolve the problem ?
I am using C# .NetCore 1.0. When I call the createNode I am getting this response object Id = 1, Status = WaitingForActivation, Method = "{null}", Result = "{Not yet computed}" and getting an error like
Exception: One or more errors occurred. (Exception of type 'org.apache.zookeeper.KeeperException+NoNodeException' was thrown.)
Please help me on this.
Regards, Ram