{"id":13620651,"url":"https://github.com/segment-boneyard/nsqjs","last_synced_at":"2025-04-14T22:32:10.319Z","repository":{"id":13929837,"uuid":"16629430","full_name":"segment-boneyard/nsqjs","owner":"segment-boneyard","description":"JavaScript fork of the coffeescript nsqjs","archived":false,"fork":true,"pushed_at":"2014-02-07T22:50:41.000Z","size":266,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":40,"default_branch":"master","last_synced_at":"2025-04-13T14:05:53.439Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"CoffeeScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"dudleycarr/nsqjs","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/segment-boneyard.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-MIT","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-02-07T22:26:50.000Z","updated_at":"2019-02-06T22:15:20.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/segment-boneyard/nsqjs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/segment-boneyard%2Fnsqjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/segment-boneyard%2Fnsqjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/segment-boneyard%2Fnsqjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/segment-boneyard%2Fnsqjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/segment-boneyard","download_url":"https://codeload.github.com/segment-boneyard/nsqjs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248971986,"owners_count":21191704,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T21:00:58.107Z","updated_at":"2025-04-14T22:32:08.619Z","avatar_url":"https://github.com/segment-boneyard.png","language":"CoffeeScript","funding_links":[],"categories":["CoffeeScript"],"sub_categories":[],"readme":"nsqjs\n=====\nA NodeJS client for the [nsq](http://bitly.github.io/nsq/) client protocol. This implementation attempts to be\nfully compliant and maintain feature parity with the official Go ([go-nsq](https://github.com/bitly/go-nsq)) and Python ([pynsq](https://github.com/bitly/pynsq)) clients.\n\n[![Build Status](https://travis-ci.org/dudleycarr/nsqjs.png?branch=master)](https://travis-ci.org/dudleycarr/nsqjs)\n[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/dudleycarr/nsqjs/trend.png)](https://bitdeli.com/free \"Bitdeli Badge\")\n\n[![NPM](https://nodei.co/npm/nsqjs.png?downloads=true)](https://nodei.co/npm/nsqjs/)\n\nUsage\n-----\n\n### new Reader(topic, channel, options)\nThe topic and channel arguments are strings and must be specified. The options\nargument is optional. Below are the parameters that can be specified in the\noptions object.\n\n* ```maxInFlight: 1``` \u003cbr/\u003e\n  The maximum number of messages to process at once. This value is shared between nsqd connections. It's highly recommended that this value is greater than the number of nsqd connections.\n* ```heartbeatInterval: 30``` \u003cbr/\u003e\n  The frequency in seconds at which the nsqd will send heartbeats to this Reader.\n* ```maxBackoffDuration: 128``` \u003cbr/\u003e\n  The maximum amount of time (seconds) the Reader will backoff for any single backoff\n  event.\n* ```maxRetries: 5``` \u003cbr/\u003e\n  The number of times to a message can be requeued before it will be handed to the DISCARD handler and then automatically finished.\n* ```requeueDelay: 90``` \u003cbr/\u003e\n  The default amount of time (seconds) a message requeued should be delayed by before being dispatched by nsqd.\n* ```nsqdTCPAddresses``` \u003cbr/\u003e\n  A string or an array of string representing the host/port pair for nsqd instances.\n  \u003cbr/\u003e For example: `['localhost:4150']`\n* ```lookupdHTTPAddresses``` \u003cbr/\u003e\n  A string or an array of strings representing the host/port pair of nsqlookupd instaces.\n  \u003cbr/\u003e For example: `['localhost:4161']`\n* ```lookupdPollInterval: 60``` \u003cbr/\u003e\n  The frequency in seconds for querying lookupd instances.\n* ```lookupdPollJitter: 0.3``` \u003cbr/\u003e\n  The jitter applied to the start of querying lookupd instances periodically.\n\nReader events are:\n\n* `Reader.MESSAGE`\n* `Reader.DISCARD`\n\nBoth events produce a Message object.\n\n### Message\nThe following properties and methods are available on Message objects produced by a Reader\ninstance.\n\n* `timestamp` \u003cbr/\u003e\n  Numeric timestamp for the Message provided by nsqd.\n* `attempts` \u003cbr/\u003e\n  The number of attempts that have been made to process this message.\n* `id` \u003cbr/\u003e\n  The opaque string id for the Message provided by nsqd.\n* `hasResponded` \u003cbr/\u003e\n  Boolean for whether or not a response has been sent.\n* `body` \u003cbr/\u003e\n  The message payload as a Buffer object.\n* `json()` \u003cbr/\u003e\n  Parses message payload as JSON and caches the result.\n* `timeUntilTimeout(hard=false)`: \u003cbr/\u003e\n  Returns the amount of time until the message times out. If the hard argument\n  is provided, then it calculates the time until the hard timeout when nsqd\n  will requeue inspite of touch events.\n* `finish()` \u003cbr/\u003e\n  Finish the message as successful.\n* `requeue(delay=null, backoff=true)`\n  The delay is in seconds. This is how long nsqd will hold on the message\n  before attempting it again. The backoff parameter indicates that we should\n  treat this as an error within this process and we need to backoff to recover.\n* `touch()` \u003cbr/\u003e\n  Tell nsqd that you want extra time to process the message. It extends the\n  soft timeout by the normal timeout amount.\n\n### new Writer(nsqdHost, nsqdPort)\nAllows messages to be sent to an nsqd. The nsqd can be directly specified or it\ncan be discovered via lookupds.\n\nWriter events are:\n\n* `Writer.READY`\n* `Writer.CLOSED`\n\nThese methods are available on a Writer object:\n* `connect()` \u003cbr/\u003e\n  Connect to the nsqd specified or connect to a random nsqd discovered via\n  lookupd.\n* `close()` \u003cbr/\u003e\n  Disconnect from the nsqd.\n* `publish(topic, msgs)` \u003cbr/\u003e\n  `topic` is a string. `msgs` is either a string, a `Buffer`, or a list of\n  strings / `Buffers`.\n\n### Simple example\n\nStart [nsqd](http://bitly.github.io/nsq/components/nsqd.html) and\n[nsqdlookupd](http://bitly.github.io/nsq/components/nsqlookupd.html)\n```bash\n# nsqdLookupd Listens on 4161 for HTTP requests\n$ nsqlookupd \u0026\n$ nsqd \u0026\n```\n\nSample CoffeeScript client:\n```coffee-script\nnsq = require 'nsqjs'\n\ntopic = 'sample'\nchannel = 'test_channel'\noptions =\n  lookupdHTTPAddresses: '127.0.0.1:4161'\n\nreader = new nsq.Reader topic, channel, options\nreader.connect()\n\nreader.on nsq.Reader.MESSAGE, (msg) -\u003e\n  console.log \"Received message [#{msg.id}]: #{msg.body.toString()}\"\n  msg.finish()\n```\n\nPublish a message to nsqd to be consumed by the sample client:\n```bash\n$ curl -d \"it really tied the room together\" http://localhost:4151/pub?topic=sample\n```\n\n### Example with message timeouts\n\nThis script simulates a message that takes a long time to process or at least\nlonger than the default message timeout. To ensure that the message doesn't\ntimeout while being processed, touch events are sent to keep it alive.\n\n```coffee-script\n{Reader} = require 'nsqjs'\n\ntopic = 'sample'\nchannel = 'test_channel'\noptions =\n  lookupdHTTPAddresses: '127.0.0.1:4161'\n\nreader = new Reader topic, channel, options\nreader.connect()\n\nreader.on Reader.MESSAGE, (msg) -\u003e\n  console.log \"Received message [#{msg.id}]\"\n\n  touch = -\u003e\n    unless msg.hasResponded\n      console.log \"Touch [#{msg.id}]\"\n      msg.touch()\n      # Touch the message again a second before the next timeout.\n      setTimeout touch, msg.timeUntilTimeout() - 1000\n\n  finish = -\u003e\n    console.log \"Finished message [#{msg.id}]: #{msg.body.toString()}\"\n    msg.finish()\n\n  console.log \"Message timeout is #{msg.timeUntilTimeout() / 1000} secs.\"\n  setTimeout touch, msg.timeUntilTimeout() - 1000\n\n  # Finish the message after 2 timeout periods and 1 second.\n  setTimeout finish, msg.timeUntilTimeout() * 2 + 1000\n```\n\n### Enable nsqjs debugging\nIf you want to see the internal events of nsqjs, you can do so by doing the\nfollowing:\n```coffee-script\nnsq = require 'nsqjs'\nnsq.StateChangeLogger.debug = true\n```\n\n### A Writer Example\n\nThe writer sends a single message and then a list of messages.\n\n```coffee-script\n{Writer} = require 'nsqjs'\n\nw = new Writer '127.0.0.1', 4150\nw.connect()\n\nw.on Writer.READY, -\u003e\n  # Send a single message\n  w.publish 'sample_topic', 'it really tied the room together'\n  w.publish 'sample_topic', ['Uh, excuse me. Mark it zero. Next frame.', \n    'Smokey, this is not \\'Nam. This is bowling. There are rules.']\nw.on Writer.CLOSED, -\u003e\n  console.log 'Writer closed'\n```\n\nChanges\n-------\n* **0.3.1**\n  * Fixed sending an array of Buffers\n  * Fixed sending a message with multi-byte characters\n* **0.3.0**\n  * Added Writer implementation\n* **0.2.1**\n  * Added prepublish compilation to JavaScript.\n* **0.2.0**\n  * `ReaderRdy`, `ConnectionRdy` implementation\n  * `Reader` implementation\n  * Initial documentation\n  * `NSQDConnection`\n    * Moved defaults to `Reader`\n    * Support protocol / state logging\n    * `connect()` now happens on next tick so that it can be called before event\n      handlers are registered.\n  * `Message`\n    * Correctly support `TOUCH` events\n    * Support soft and hard timeout timings\n    * JSON parsing of message body\n* **0.1.0**\n  * `NSQDConnection` implementation\n  * `wire` implementation\n  * `Message` implementation\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsegment-boneyard%2Fnsqjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsegment-boneyard%2Fnsqjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsegment-boneyard%2Fnsqjs/lists"}