AsyncConn – a connection to nsqd

class nsq.AsyncConn(host, port, timeout=1.0, heartbeat_interval=30, requeue_delay=90, tls_v1=False, tls_options=None, snappy=False, deflate=False, deflate_level=6, user_agent=u'pynsq/0.7.0', output_buffer_size=16384, output_buffer_timeout=250, sample_rate=0, io_loop=None, auth_secret=None, msg_timeout=None)

Low level object representing a TCP connection to nsqd.

When a message on this connection is requeued and the requeue delay has not been specified, it calculates the delay automatically by an increasing multiple of requeue_delay.

Generates the following events that can be listened to with nsq.AsyncConn.on():

  • connect
  • close
  • error
  • identify
  • identify_response
  • auth
  • auth_response
  • heartbeat
  • ready
  • message
  • response
  • backoff
  • resume
  • host – the host to connect to
  • port – the post to connect to
  • timeout – the timeout for read/write operations (in seconds)
  • heartbeat_interval – the amount of time (in seconds) to negotiate with the connected producers to send heartbeats (requires nsqd 0.2.19+)
  • requeue_delay – the base multiple used when calculating requeue delay (multiplied by # of attempts)
  • tls_v1 – enable TLS v1 encryption (requires nsqd 0.2.22+)
  • tls_options – dictionary of options to pass to ssl.wrap_socket() as **kwargs
  • snappy – enable Snappy stream compression (requires nsqd 0.2.23+)
  • deflate – enable deflate stream compression (requires nsqd 0.2.23+)
  • deflate_level – configure the deflate compression level for this connection (requires nsqd 0.2.23+)
  • output_buffer_size – size of the buffer (in bytes) used by nsqd for buffering writes to this connection
  • output_buffer_timeout – timeout (in ms) used by nsqd before flushing buffered writes (set to 0 to disable). Warning: configuring clients with an extremely low (< 25ms) output_buffer_timeout has a significant effect on nsqd CPU usage (particularly with > 50 clients connected).
  • sample_rate – take only a sample of the messages being sent to the client. Not setting this or setting it to 0 will ensure you get all the messages destined for the client. Sample rate can be greater than 0 or less than 100 and the client will receive that percentage of the message traffic. (requires nsqd 0.2.25+)
  • user_agent – a string identifying the agent for this client in the spirit of HTTP (default: <client_library_name>/<version>) (requires nsqd 0.2.25+)
  • auth_secret – a string passed when using nsq auth (requires nsqd 1.0+)
  • msg_timeout – the amount of time (in seconds) that nsqd will wait before considering messages that have been delivered to this consumer timed out (requires nsqd 0.2.28+)
off(name, callback)

Stop listening for the named event via the specified callback.

  • name (string) – the name of the event
  • callback (callable) – the callback that was originally used
on(name, callback)

Listen for the named event with the specified callback.

  • name (string) – the name of the event
  • callback (callable) – the callback to execute when the event is triggered
trigger(name, *args, **kwargs)

Execute the callbacks for the listeners on the specified event with the supplied arguments.

All extra arguments are passed through to each callback.

Parameters:name (string) – the name of the event