Signals¶
Both Consumer and NsqdTCPClient classes expose various signals provided by the Blinker library.
Subscribing to signals¶
To subscribe to a signal, you can use the
connect()
method of a signal. The first
argument is the function that should be called when the signal is emitted,
the optional second argument specifies a sender. To unsubscribe from a
signal, you can use the disconnect()
method.
def error_handler(consumer, error):
print 'Got an error:', error
consumer.on_error.connect(error_handler)
You can also easily subscribe to signals by using
connect()
as a decorator:
@consumer.on_giving_up.connect
def handle_giving_up(consumer, message):
print 'Giving up on:', message.id