diff --git a/src/listen/ClientWorker.cpp b/src/listen/ClientWorker.cpp index 6e58c68..b3a1088 100644 --- a/src/listen/ClientWorker.cpp +++ b/src/listen/ClientWorker.cpp @@ -319,6 +319,8 @@ NacosString ClientWorker::checkListenedKeys() NACOS_THROW(NetworkException,Nacos paramValues.push_back(ConfigConstant::PROBE_MODIFY_REQUEST); paramValues.push_back(postData); log_debug("[ClientWorker]-checkListenedKeys:Assembled postData:%s\n", postData.c_str()); + paramValues.push_back("tenant"); + paramValues.push_back(_objectConfigData->_serverListManager->getNamespace()); //Get the request url //TODO:move /listener to constant diff --git a/testfawsw/IntegratingIntoYourProject.cpp b/testfawsw/IntegratingIntoYourProject.cpp new file mode 100644 index 0000000..26acf63 --- /dev/null +++ b/testfawsw/IntegratingIntoYourProject.cpp @@ -0,0 +1,107 @@ +#include "factory/NacosServiceFactory.h" + +#include +#include +#include "Nacos.h" +#include "log/Logger.h" + +using namespace std; +using namespace nacos; + +class MyListener : public Listener { +private: + int num; +public: + MyListener(int num) { + this->num = num; + } + + void receiveConfigInfo(const NacosString &configInfo) { + cout << "===================================" << endl; + cout << "Watcher" << num << endl; + cout << "Watched Key UPDATED:" << configInfo << endl; + cout << "===================================" << endl; + } +}; + +int main() { + Logger::setLogLevel(DEBUG); + Properties configProps; + // configProps[PropertyKeyConst::SERVER_ADDR] = ""; + // configProps[PropertyKeyConst::AUTH_USERNAME] = "test"; + // configProps[PropertyKeyConst::AUTH_PASSWORD] = "test"; + // configProps[PropertyKeyConst::NAMESPACE] = "dev"; + // configProps[PropertyKeyConst::SERVER_ADDR] = ""; + // configProps[PropertyKeyConst::AUTH_USERNAME] = "hqzl3"; + // configProps[PropertyKeyConst::AUTH_PASSWORD] = "sitHqzl3nacos2022"; + // configProps[PropertyKeyConst::NAMESPACE] = "fc2-faw-szhb-hqzl3"; + NacosServiceFactory *factory = new NacosServiceFactory(configProps); + ResourceGuard _guardFactory(factory); + + + // NamingService *namingSvc = factory->CreateNamingService(); + // ResourceGuard _serviceFactory(namingSvc); + // Instance instance; + // instance.clusterName = "DefaultCluster"; + // instance.ip = "127.0.0.1"; + // instance.port = 2333; + // instance.instanceId = "1"; + // instance.ephemeral = true; + + //Registers 5 services named TestNamingService1...5 + // try { + // for (int i = 0; i < 5; i++) { + // NacosString serviceName = "TestNamingService" + NacosStringOps::valueOf(i); + // instance.port = 2000 + i; + // namingSvc->registerInstance(serviceName, instance); + // } + // } + // catch (NacosException &e) { + // cout << "encounter exception while registering service instance, raison:" << e.what() << endl; + // return -1; + // } + // sleep(30); + // try { + // for (int i = 0; i < 5; i++) { + // NacosString serviceName = "TestNamingService" + NacosStringOps::valueOf(i); + + // namingSvc->deregisterInstance(serviceName, "127.0.0.1", 2000 + i); + // sleep(1); + // } + // } + // catch (NacosException &e) { + // cout << "encounter exception while registering service instance, raison:" << e.what() << endl; + // return -1; + // } + // sleep(30); + + // return 0; + + ConfigService *n = factory->CreateConfigService(); + ResourceGuard _serviceFactory(n); + + MyListener *theListener = new MyListener(1);//You don't need to free it, since it will be deleted by the function removeListener + n->addListener("tts-script.yaml", "nlu", theListener);//All changes on the key dqid will be received by MyListener + + cout << "Input a character to continue" << endl; + getchar(); + cout << "remove listener" << endl; + n->removeListener("tts-script.yaml", "nlu", theListener);//Cancel listening + getchar(); + + return 0; + + // NacosString ss = ""; + // try { + // ss = n->getConfig("tts-script.yaml", "nlu", 10000); + // } + // catch (NacosException &e) { + // cout << + // "Request failed with curl code:" << e.errorcode() << endl << + // "Reason:" << e.what() << endl; + // return -1; + // } + // cout << ss << endl; + + // return 0; +} \ No newline at end of file diff --git a/testfawsw/README.md b/testfawsw/README.md new file mode 100644 index 0000000..c018d68 --- /dev/null +++ b/testfawsw/README.md @@ -0,0 +1,20 @@ +``` +cd nacos-sdk-cpp +cmake . +make +``` + +``` +NacosServiceFactory.h +Mutex.h +Tid.h +TimeUtils.h +以上4个头文件需要从src源码中拷贝到`usr/local/include/nacos/`目录, +拷贝位置要和src保持一致, +同时修改以上头文件的的`include`使用相对路径 +``` + +``` +g++ -I/usr/local/include/nacos/ IntegratingIntoYourProject.cpp -lnacos-cli -o integrated.out +./integrated.out +``` \ No newline at end of file