diff --git a/apps/evnsq/nsq_conn.cc b/apps/evnsq/nsq_conn.cc index 9cd458033..0d4e3b141 100644 --- a/apps/evnsq/nsq_conn.cc +++ b/apps/evnsq/nsq_conn.cc @@ -37,6 +37,8 @@ NSQConn::~NSQConn() { void NSQConn::Connect(const std::string& addr) { DLOG_TRACE << " remote_addr=" << addr; tcp_client_ = evpp::TCPClientPtr(new evpp::TCPClient(loop_, addr, std::string("NSQClient-") + addr)); + tcp_client_->set_auto_reconnect(option_.auto_reconnect_); + tcp_client_->set_reconnect_interval(option_.reconnect_interval_); status_ = kConnecting; tcp_client_->SetConnectionCallback(std::bind(&NSQConn::OnTCPConnectionEvent, this, std::placeholders::_1)); tcp_client_->SetMessageCallback(std::bind(&NSQConn::OnRecv, this, std::placeholders::_1, std::placeholders::_2)); diff --git a/apps/evnsq/option.cc b/apps/evnsq/option.cc index e2128f510..029ed468d 100644 --- a/apps/evnsq/option.cc +++ b/apps/evnsq/option.cc @@ -8,7 +8,13 @@ namespace evnsq { Option::Option() { - // hostname = "evnsq.localhost.com"; // TODO get hostname + // hostname = "evnsq.localhost.com"; // TODO get hostname +} + +void Option::setReconnect(bool auto_reconnect, evpp::Duration reconnect_interval) +{ + auto_reconnect_ = auto_reconnect; + reconnect_interval_ = reconnect_interval; } std::string Option::ToJSON() const { diff --git a/apps/evnsq/option.h b/apps/evnsq/option.h index e761f42b7..165ba15be 100644 --- a/apps/evnsq/option.h +++ b/apps/evnsq/option.h @@ -12,6 +12,7 @@ namespace evnsq { struct EVNSQ_EXPORT Option { public: Option(); + void setReconnect(bool auto_reconnect, evpp::Duration reconnect_interval); std::string ToJSON() const; public: @@ -45,5 +46,7 @@ struct EVNSQ_EXPORT Option { // Integer percentage to sample the channel (requires nsqd 0.2.25+) // min:"0" max : "99" int sample_rate = 0; + bool auto_reconnect_ = true; // The flag whether it reconnects automatically, Default : true + evpp::Duration reconnect_interval_ = evpp::Duration(3.0); // Default : 3 seconds }; }