提交 bd8bd035 authored 作者: blu's avatar blu

init

上级 0352f0aa
......@@ -118,8 +118,7 @@ private:
if(!found) {
spdlog::error("evslicer {}: no valid config found. retrying load config...", devSn);
this_thread::sleep_for(chrono::seconds(3));
continue;
goto togo_sc;
}
selfId = devSn + ":evslicer:" + to_string(iid);
......@@ -159,50 +158,12 @@ private:
ret = system((string("mkdir -p ") + urlOut).c_str());
if(ret == -1) {
spdlog::error("failed to create {} dir", urlOut);
return -1;
exit(1);
}
urlPub = string("tcp://") + evpuller["addr"].get<string>() + ":" + to_string(evpuller["port-pub"]);
urlRouter = string("tcp://") + evmgr["addr"].get<string>() + ":" + to_string(evmgr["port-router"]);
spdlog::info("evslicer {} will connect to {} for sub, {} for router", selfId, urlPub, urlRouter);
}
catch(exception &e) {
spdlog::error("evslicer {} exception in init {:s} retrying", selfId, e.what());
this_thread::sleep_for(chrono::seconds(3));
continue;
}
inited = true;
}
return 0;
}
int ping()
{
// send hello to router
int ret = 0;
vector<vector<uint8_t> >body;
// since identity is auto set
body.push_back(str2body(mgrSn+":0:0"));
body.push_back(str2body(EV_MSG_META_PING)); // blank meta
body.push_back(str2body(MSG_HELLO));
ret = z_send_multiple(pDealer, body);
if(ret < 0) {
spdlog::error("evslicer {} failed to send multiple: {}", selfId, zmq_strerror(zmq_errno()));
//TODO:
}
else {
spdlog::info("evslicer {} sent hello to router: {}", selfId, mgrSn);
}
return ret;
}
int setupMq()
{
int ret = 0;
// setup sub
pSubCtx = zmq_ctx_new();
......@@ -210,12 +171,12 @@ private:
ret = zmq_setsockopt(pSub, ZMQ_SUBSCRIBE, "", 0);
if(ret != 0) {
spdlog::error("evslicer {} failed set setsockopt: {}", selfId, urlPub);
return -1;
goto togo_sc;
}
ret = zmq_connect(pSub, urlPub.c_str());
if(ret != 0) {
spdlog::error("evslicer {} failed connect pub: {}", selfId, urlPub);
return -2;
goto togo_sc;
}
// setup dealer
......@@ -226,28 +187,53 @@ private:
ret += zmq_setsockopt (pDealer, ZMQ_ROUTING_ID, selfId.c_str(), selfId.size());
if(ret < 0) {
spdlog::error("evpusher {} {} failed setsockopts router: {}", selfId, urlRouter);
return -3;
goto togo_sc;
}
if(ret < 0) {
spdlog::error("evslicer {} failed setsockopts router: {}", selfId, urlRouter);
return -3;
goto togo_sc;
}
ret = zmq_connect(pDealer, urlRouter.c_str());
if(ret != 0) {
spdlog::error("evslicer {} failed connect dealer: {}", selfId, urlRouter);
return -4;
goto togo_sc;
}
//ping
ret = ping();
// TODO: don't need this anymore, since I've used the draft feature of ZOUTER_NOTIFICATION instead
// thPing = thread([&,this]() {
// while(true) {
// this_thread::sleep_for(chrono::seconds(EV_HEARTBEAT_SECONDS-2));
// ping();
// }
// });
}
catch(exception &e) {
spdlog::error("evslicer {} exception in init {:s} retrying", selfId, e.what());
this_thread::sleep_for(chrono::seconds(3));
continue;
}
inited = true;
break;
togo_sc:
this_thread::sleep_for(chrono::seconds(3));
continue;
}
return ret;
}
// thPing.detach();
int ping()
{
// send hello to router
int ret = 0;
vector<vector<uint8_t> >body;
// since identity is auto set
body.push_back(str2body(mgrSn+":0:0"));
body.push_back(str2body(EV_MSG_META_PING)); // blank meta
body.push_back(str2body(MSG_HELLO));
ret = z_send_multiple(pDealer, body);
if(ret < 0) {
spdlog::error("evslicer {} failed to send multiple: {}", selfId, zmq_strerror(zmq_errno()));
//TODO:
}
else {
spdlog::info("evslicer {} sent hello to router: {}", selfId, mgrSn);
}
return ret;
}
......@@ -485,7 +471,6 @@ public:
EvSlicer()
{
init();
setupMq();
getInputFormat();
setupStream();
};
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论