diff --git a/include/amqpcpp/connectionhandler.h b/include/amqpcpp/connectionhandler.h index 7b0d3c1..d024f90 100644 --- a/include/amqpcpp/connectionhandler.h +++ b/include/amqpcpp/connectionhandler.h @@ -204,9 +204,10 @@ public: * disk space, another notification will not be sent. * * @param connection The connection that was blocked + * @param reason Why was the connection blocked */ - virtual void onBlocked(Connection *connection) - { + virtual void onBlocked(Connection *connection, const char *reason) + { // make sure compilers dont complain about unused parameters (void) connection; } diff --git a/include/amqpcpp/connectionimpl.h b/include/amqpcpp/connectionimpl.h index 4020564..c38b723 100644 --- a/include/amqpcpp/connectionimpl.h +++ b/include/amqpcpp/connectionimpl.h @@ -430,11 +430,12 @@ public: /** * Report that the connection is blocked + * @param reason */ - void reportBlocked() + void reportBlocked(const char *reason) { // inform the handler - _handler->onBlocked(_parent); + _handler->onBlocked(_parent, reason); } /** diff --git a/include/amqpcpp/linux_tcp/tcpconnection.h b/include/amqpcpp/linux_tcp/tcpconnection.h index 95e3f4d..7cfd533 100644 --- a/include/amqpcpp/linux_tcp/tcpconnection.h +++ b/include/amqpcpp/linux_tcp/tcpconnection.h @@ -116,7 +116,28 @@ private: * @param connection The connection that was closed and that is now unusable */ virtual void onClosed(Connection *connection) override; - + + /** + * Method that is called when the AMQP connection was blocked. + * @param connection The connection that was blocked + * @param reason Why was the connection blocked + */ + virtual void onBlocked(Connection *connection, const char *reason) override + { + // pass to user space + if (_handler) _handler->onBlocked(this, reason); + } + + /** + * Method that is called when the AMQP connection is no longer blocked. + * @param connection The connection that is no longer blocked + */ + virtual void onUnblocked(Connection *connection) + { + // pass to user space + if (_handler) _handler->onUnblocked(this); + } + /** * Method that is called when the tcp connection has been established * @param state diff --git a/include/amqpcpp/linux_tcp/tcphandler.h b/include/amqpcpp/linux_tcp/tcphandler.h index 2322a02..2389e4c 100644 --- a/include/amqpcpp/linux_tcp/tcphandler.h +++ b/include/amqpcpp/linux_tcp/tcphandler.h @@ -190,7 +190,40 @@ public: // make sure compilers dont complain about unused parameters (void) connection; } - + + /** + * Method that is called when the AMQP connection was blocked. + * + * This method is called, when the server connection gets blocked for the first + * time due to the broker running low on a resource (memory or disk). For + * example, when a RabbitMQ node detects that it is low on RAM, it sends a + * notification to all connected publishing clients supporting this feature. + * If before the connections are unblocked the node also starts running low on + * disk space, another notification will not be sent. + * + * @param connection The connection that was blocked + * @param reason Why was the connection blocked + */ + virtual void onBlocked(TcpConnection *connection, const char *reason) + { + // make sure compilers dont complain about unused parameters + (void) connection; + } + + /** + * Method that is called when the AMQP connection is no longer blocked. + * + * This method is called when all resource alarms have cleared and the + * connection is fully unblocked. + * + * @param connection The connection that is no longer blocked + */ + virtual void onUnblocked(TcpConnection *connection) + { + // make sure compilers dont complain about unused parameters + (void) connection; + } + /** * Method that is called when the TCP connection is lost or closed. This * is always called if you have also received a call to onConnected(). diff --git a/src/connectionblockframe.h b/src/connectionblockframe.h index a9c614b..ab789df 100644 --- a/src/connectionblockframe.h +++ b/src/connectionblockframe.h @@ -94,7 +94,7 @@ public: virtual bool process(ConnectionImpl *connection) override { // report that it is blocked - connection->reportBlocked(); + connection->reportBlocked(this->reason().c_str()); // done return true;