# Building NSQ Client Libraries

DevFeed: [Building NSQ Client Libraries](<https://devfeed.tech/articles/building-nsq-client-libraries-19702.md>)

Original publisher: [Read original article](<https://word.bitly.com/post/50027069647>)

Author: Wordbitly

Published: 2013-05-09T18:58:23Z

Content type: tutorial

Language: en

Sources: [Bitly](<https://devfeed.tech/sources/bitly.md>)

Topics: [Messaging](<https://devfeed.tech/topics/messaging.md>), [client](<https://devfeed.tech/topics/client.md>), [configuration](<https://devfeed.tech/topics/configuration.md>), [servers](<https://devfeed.tech/topics/servers.md>), [HTTP](<https://devfeed.tech/topics/http.md>)

Tags: [asynchronous](<https://devfeed.tech/tags/asynchronous.md>), [client-library](<https://devfeed.tech/tags/client-library.md>), [configuration](<https://devfeed.tech/tags/configuration.md>), [developers](<https://devfeed.tech/tags/developers.md>), [distributed](<https://devfeed.tech/tags/distributed.md>), [guide](<https://devfeed.tech/tags/guide.md>), [infrastructure](<https://devfeed.tech/tags/infrastructure.md>), [message-queue](<https://devfeed.tech/tags/message-queue.md>), [messaging](<https://devfeed.tech/tags/messaging.md>), [nsq](<https://devfeed.tech/tags/nsq.md>), [tcp](<https://devfeed.tech/tags/tcp.md>), [thundering-herd](<https://devfeed.tech/tags/thundering-herd.md>)

## AI overview

A guide to the responsibilities and design expectations of NSQ client libraries, focusing on consumers. It covers configuration, discovery, TCP connections, message handling, pipelining, asynchronous processing, and techniques for maintaining cluster robustness and performance.

## Source excerpt

Brace yourself, this is a long one. The following guide was originally intended for client library developers to describe in detail all the important features and functionality we expected in an NSQ client library. While writing it we began to realize that it had value beyond client library developers. It incorporates a comprehensive analysis of most of the capabilities of NSQ (both client and server) and is therefore interesting and useful for end-users as well (or anyone using or interested in infrastructure messaging platforms). If you need some background on NSQ please see our original blog post or its follow up, spray some NSQ on it. Intro NSQ's design pushes a lot of responsibility onto client libraries in order to maintain overall cluster robustness and performance. This guide attempts to outline the various responsibilities well-behaved client libraries need to fulfill. Because publishing to nsqd is trivial (just an HTTP POST to the /put endpoint), this document focuses on consumers. By setting these expectations we hope to provide a foundation for achieving consistency across languages for NSQ users. Overview Configuration Discovery (optional) Connection Handling Feature Negotiation Data Flow / Heartbeats Message Handling RDY State Backoff Configuration At a high level, our philosophy with respect to configuration is to design the system to have the flexibility to support different workloads, use sane defaults that run well "out of the box", and minimize the number of dials. A client subscribes to a topic on a channel over a TCP connection to nsqd instance(s). You can only subscribe to one topic per connection so multiple topic consumption needs to be structured accordingly. Using nsqlookupd for discovery is optional so client libraries should support a configuration where a client connects directly to one or more nsqd instances or where it is configured to poll one or more nsqlookupd instances. When a client is configured to poll nsqlookupd the polling int