nsq-topics
v1.1.0
Published
Nsq helper to poll a nsqlookupd service for all it's topics and mirror it locally.
Downloads
50
Readme
nsq-topics
Nsq helper to poll a nsqlookupd service for all it's topics and mirror it locally.
INFO: all examples are written in coffee-script
Install
npm install nsq-topics
Initialize
new NsqTopics( config );
Example:
var NsqTopics = require( "nsq-topics" )
var topics = new NsqTopics({
// Listen to two local nsq lookupservers
"lookupdHTTPAddresses": [ "127.0.0.1:4161", "127.0.0.1:4163" ]
});
// get the current list of topics
topics.list( function( err, topics ){
if( err ){
// handle the error
}
console.log( topics ) // -> an array of topics. E.g.: ( )`users`, `logins`, ... )
// listen for new topics
topics.on( "add", function( topic ){
// called until a new topic arrived
});
// listen for removed topics
topics.on( "remove", function( topic ){
// called until a topic was removed
});
// listen for topic list changes
topics.on( "change", function( topicList ){
// beside the `add` and `remove` events a single "change" event will be emitted
});
// setting a filter to only listen to specific topics
topics.filter( [ "user", "logins", "posts" ] );
// listen for errors
topics.on( "error", function( err ){
// E.g. called if a invalid filter was used or no lookup server is available
});
});
Config
- lookupdHTTPAddresses : (
String|String[]
required ) A single or multiple nsqlookupd hosts. This is also a configuration of 'nsqjs' - lookupdPollInterval : (
Number
optional: default =60
) Time in seconds to poll the nsqlookupd servers to sync the available topics. This is also a configuration of 'nsqjs' - topicFilter : (
Null|String|Array|RegExp|Function
optional: default =null
) A filter to reduce the returned topics - active : (
Boolean
optional: default =true
) Configuration to (de)activate the nsq topics on startup
Methods
.activate()
Activate the module
Return
( Boolean ): true
if it is now activated. false
if it was already active
.deactivate()
Deactivate the module
Return
( Boolean ): true
if it is now deactivated. false
if it was already inactive
.active()
Test if the module is currently active
Return
( Boolean ): Is active?
.list( cb )
Get a list of the current topics
cb
: (Function
optional ): Callback to get the list of topics
Return
( Self ): The instance itself for chaining.
Example:
topics.list( function( err, topics ){
if( err ){
// handle the error
}
console.log( topics ) // -> an array of topics. E.g.: ( )`users`, `logins`, ... )
});
Events
add
A new topic was added
Arguments
- topic : (
String
) The new topic
Example:
topics.on( "add", function( topic ){
// called until a new topic arrived
});
remove
A existing topic was removed
Arguments
- topic : (
String
) The removed topic
Example:
topics.on( "remove", function( topic ){
// called until a topic was removed
});
change
The list of topics changed
Arguments
- topics : (
String[]
) A list of current topics
Example:
topics.on( "change", function( topicList ){
// beside the `add` and `remove` events a single "change" event will be emitted
});
error
An error occurred. E.g. called if a invalid filter was used or no lookup server is available
Arguments
- err : (
Error
) The error object.
Example:
topics.on( "error", function( err ){
// handle the error
});
ready
Emitted once the list of topics where received the first time.
This is just an internal helper. The Method list
will also wait for the first response. The events add
, remove
and change
are active after this first response.
Example:
topics.on( "ready", function( err ){
// handle the error
});
Release History
|Version|Date|Description| |:--:|:--:|:--| |1.1.0|2019-01-25|now able to handle the formats of nsq < and > 1.x| |1.0.0|2019-01-25|updated topic response handler to match nsq >= 1.x format| |0.0.6|2018-11-17|Updated dependencies| |0.0.5|2016-07-18|Updated dependencies and removed generated code docs from repo| |0.0.4|2016-05-09|Updated dependencies. Especially lodash to 4.x| |0.0.3|2016-02-19|Fixed default configuration| |0.0.2|2015-11-30|Bugfixes; Tests; Docs| |0.0.1|2015-11-27|Initial commit|
Initially Generated with generator-mpnodemodule
Other projects
|Name|Description| |:--|:--| |nsq-logger|Nsq service to read messages from all topics listed within a list of nsqlookupd services.| |nsq-nodes|Nsq helper to poll a nsqlookupd service for all it's nodes and mirror it locally.| |nsq-watch|Watch one or many topics for unprocessed messages.| |node-cache|Simple and fast NodeJS internal caching. Node internal in memory cache like memcached.| |rsmq|A really simple message queue based on redis| |redis-heartbeat|Pulse a heartbeat to redis. This can be used to detach or attach servers to nginx or similar problems.| |systemhealth|Node module to run simple custom checks for your machine or it's connections. It will use redis-heartbeat to send the current state to redis.| |rsmq-cli|a terminal client for rsmq| |rest-rsmq|REST interface for.| |redis-sessions|An advanced session store for NodeJS and Redis| |connect-redis-sessions|A connect or express middleware to simply use the redis sessions. With redis sessions you can handle multiple sessions per user_id.| |redis-notifications|A redis based notification engine. It implements the rsmq-worker to safely create notifications and recurring reports.| |hyperrequest|A wrapper around hyperquest to handle the results| |task-queue-worker|A powerful tool for background processing of tasks that are run by making standard http requests |soyer|Soyer is small lib for server side use of Google Closure Templates with node.js.| |grunt-soy-compile|Compile Goggle Closure Templates ( SOY ) templates including the handling of XLIFF language files.| |backlunr|A solution to bring Backbone Collections together with the browser fulltext search engine Lunr.js| |domel|A simple dom helper if you want to get rid of jQuery| |obj-schema|Simple module to validate an object by a predefined schema|
The MIT License (MIT)
Copyright © 2015 M. Peter, http://www.tcs.de
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.