C++ zookeeper库使用示例

这篇博客分享了作者在使用C++操作Zookeeper时的经验,提供了一份自编写的zkClient示例代码,旨在帮助读者更好地理解和应用Zookeeper库。
摘要由CSDN通过智能技术生成

从网上找了一个示例程序,但是用的不是很好,其中还有点问题,最后根据我自己的使用贴一个示例,希望能给大家学习时提供点参考:
zkClient.h

#pragma once
#include "../zookeeper/zookeeper.h"
#include <iostream>
#include <sstream>
#include <string>
#include <unistd.h>
#include <fcntl.h>
#include <map>
#include <vector>
#include <list>
using namespace std;
#define ONE_SECONDS 1000*1

class zkClient
{
   
public:
    zkClient(void);
    ~zkClient(void);
public:

    void ConnectZK(const std::string& strzkServerIP,int nPort);//连接Zk
    void ConnectZK(std::string strzkServer);//连接Zk
    void Update();
    void SetNodePath(std::string strNodePath);
public:
    zhandle_t *m_zhandle;
    bool connected;
private:
    std::string m_strNodePath;
    std::string m_strServerIP;
    int nPort;
};

zkClient.cpp

//#include "StdAfx.h"
#include "zkClient.h"
#include <glog/logging.h>
#include "../Json/JsonBase.h"
#include "ctool.h"
#include <string.h>
#include "protocol.h"

using namespace std;
#define random(a,b) (rand()%(b-a+1)+a)
void InitWatcher(zhandle_t *zh, int type, int state, const char 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值