Skip to content

Commit

Permalink
Add Connection.Blocked callback registration methods #476
Browse files Browse the repository at this point in the history
While it was possible to manually register these callbacks without these methods, this will make it more clear for developers on how to do so.
  • Loading branch information
gmr committed Apr 29, 2015
1 parent c15b5c1 commit 765107d
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions pika/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,9 +547,11 @@ class should not be invoked directly but rather through the use of an
"""
ON_CONNECTION_BACKPRESSURE = '_on_connection_backpressure'
ON_CONNECTION_BLOCKED = '_on_connection_blocked'
ON_CONNECTION_CLOSED = '_on_connection_closed'
ON_CONNECTION_ERROR = '_on_connection_error'
ON_CONNECTION_OPEN = '_on_connection_open'
ON_CONNECTION_UNBLOCKED = '_on_connection_unblocked'
CONNECTION_CLOSED = 0
CONNECTION_INIT = 1
CONNECTION_PROTOCOL = 2
Expand Down Expand Up @@ -623,6 +625,30 @@ def add_on_close_callback(self, callback_method):
self.callbacks.add(0, self.ON_CONNECTION_CLOSED, callback_method,
False)

def add_on_connection_blocked_callback(self, callback_method):
"""Add a callback to be notified when RabbitMQ has sent a
``Connection.Blocked`` frame indicating that RabbitMQ is low on
resources. Publishers can use this to voluntarily suspend publishing,
instead of relying on back pressure throttling. The callback
will bet passed the ``Connection.Blocked`` method frame.
:param method callback_method: Callback to call on close
"""
self.callbacks.add(0, spec.Connection.Blocked, callback_method, False)

def add_on_connection_unblocked_callback(self, callback_method):
"""Add a callback to be notified when RabbitMQ has sent a
``Connection.Unblocked`` frame letting publishers know it's ok
to start publishing again. The callback will be passed the
``Connection.Unblocked`` method frame.
:param method callback_method: Callback to call on close
"""
self.callbacks.add(0, spec.Connection.Unblocked, callback_method,
False)

def add_on_open_callback(self, callback_method):
"""Add a callback notification when the connection has opened.
Expand Down

0 comments on commit 765107d

Please sign in to comment.