Skip to content

Commit

Permalink
Add heartbeat support (see https://www.rabbitmq.com/heartbeats.html)
Browse files Browse the repository at this point in the history
  • Loading branch information
reunanen committed Sep 28, 2018
1 parent ad520ed commit 55ff3a0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions include/AMQPcpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);



Expand Down
12 changes: 6 additions & 6 deletions src/AMQP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand All @@ -31,7 +31,7 @@ AMQP::AMQP(string cnnStr, bool use_ssl_,

AMQP::init(proto);
AMQP::parseCnnString(cnnStr);
AMQP::connect();
AMQP::connect(heartbeat);
};

AMQP::~AMQP() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down

2 comments on commit 55ff3a0

@abhishek22j06
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to handle heartbeat frame from RabbitMQ.

@reunanen
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abhishek22j06 I hope the C library readily handles it.

Please sign in to comment.