Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/evnsq/nsq_conn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
8 changes: 7 additions & 1 deletion apps/evnsq/option.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions apps/evnsq/option.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
};
}