diff --git a/include/AMQPcpp.h b/include/AMQPcpp.h index 1d7ba68..e452fba 100644 --- a/include/AMQPcpp.h +++ b/include/AMQPcpp.h @@ -289,7 +289,7 @@ class AMQP { AMQP(); AMQP(std::string cnnStr, bool use_ssl_=false, std::string cacert_path_="", std::string client_cert_path_="", std::string client_key_path_="", - bool verify_peer_=false, bool verify_hostname_=false); + bool verify_peer_=false, bool verify_hostname_=false, int heartbeat = 0); ~AMQP(); AMQPExchange * createExchange(); @@ -309,12 +309,12 @@ class AMQP { private: void init(enum AMQPProto_e proto); void initDefault(enum AMQPProto_e proto); - void connect(); + void connect(int heartbeat = 0); void parseCnnString(std::string cnnString ); void parseHostPort(std::string hostPortString ); void parseUserStr(std::string userString ); void sockConnect(); - void login(); + void login(int heartbeat); diff --git a/src/AMQP.cpp b/src/AMQP.cpp index 459e30f..482c963 100644 --- a/src/AMQP.cpp +++ b/src/AMQP.cpp @@ -20,7 +20,7 @@ AMQP::AMQP() { AMQP::AMQP(string cnnStr, bool use_ssl_, string cacert_path_, string client_cert_path_, string client_key_path_, - bool verify_peer_, bool verify_hostname_) { + bool verify_peer_, bool verify_hostname_, int heartbeat) { use_ssl = use_ssl_; proto = SET_AMQP_PROTO_BY_SSL_USAGE(use_ssl); cacert_path = cacert_path_; @@ -31,7 +31,7 @@ AMQP::AMQP(string cnnStr, bool use_ssl_, AMQP::init(proto); AMQP::parseCnnString(cnnStr); - AMQP::connect(); + AMQP::connect(heartbeat); }; AMQP::~AMQP() { @@ -159,9 +159,9 @@ void AMQP::parseHostPort(string hostPortString ) { } } -void AMQP::connect() { +void AMQP::connect(int heartbeat) { AMQP::sockConnect(); - AMQP::login(); + AMQP::login(heartbeat); } void AMQP::printConnect() { @@ -220,8 +220,8 @@ void AMQP::sockConnect() { } } -void AMQP::login() { - amqp_rpc_reply_t res = amqp_login(cnn, vhost.c_str(), 0, FRAME_MAX, 0, AMQP_SASL_METHOD_PLAIN, user.c_str(), password.c_str()); +void AMQP::login(int heartbeat) { + amqp_rpc_reply_t res = amqp_login(cnn, vhost.c_str(), 0, FRAME_MAX, heartbeat, AMQP_SASL_METHOD_PLAIN, user.c_str(), password.c_str()); if ( res.reply_type != AMQP_RESPONSE_NORMAL) { const AMQPException exception(&res); amqp_destroy_connection(cnn);