npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nsq-service

v0.1.1

Published

Inner service wrapper using NSQ, help to host distributed modules by communicating through NSQ

Downloads

4

Readme

Introduction

A Micro-Service architecture solution using MessageQueue (Currently, mainly using NSQ)

Quick start

####1. build business logic of each module in its manager.js file with fixed parameter formation: must contain 2 parameters, first is the data object, second is the callback function The manager.js file should look like this:

module.exports = {
    some_api : function( parameterObject, callback ){
       // some business logic
       // ...
    },
    
    some_other_api: function( parameterObject, callback ){
       // some other business logic
       // ...
    },

    // ...   
}

It's just suggested to use manager.js as the business logic file name, to compliant with the concept of manager which will be used in the later step

####2. Setup the NSQ configurations The configuration should look like this:

nsqServiceConfig: {
        address: '127.0.0.1',      // NSQ server address
        writerPort: 4150,          // NSQ writer port, default is 4150
        readerPort: 4150,          // NSQ reader port, default is 4150
        maxInFlight: 1,            // NSQ parameter `maxInFlight`
        maxAttempts: 5,            // NSQ parameter `maxAttempts`
        producerQueue: 'auth',     // Define the name of `producer` queue
        customerQueue: 'auth-cust',// Define the name of `customer` queue
        channel: 'main'            // Default NSQ Channel is `main`
}

####3. Start NSQ-Service In the very beginning of your project entry file, normally is app.js,

var app = require('express')    // or restify, koa, etc.
// ...
var NS = require('nsq-service')
NS.queue.setConfig( nsqServiceConfig )   // the config object defined above
NS.handler.addManager(require('./PATH/TO/MANAGER')) // add some manager
NS.handler.ready( function() {      
    // NSQ-service need to be ready before start the local service
    // ...
    app.listen(3000)
})

Concepts

####1. Producer and Customer Every module in a distributed architecture is a Producer and at the mean time, is a Customer too. The communication sequence is:

(1) module[A] want to invoke an api of module[B], module[A] will send a message to module[B]'s producerQueue, in that message, information of module[A]'s customerQueue is attached

(2) module[B] receive that message from module[A], parse the api and arguments out, invoke the specified api with those arguments, when finished, module[B] send the result back to module[A]'s customerQueue, according to the attached information

(3) module[A] receive the execution result, from its customerQueue, and then execute the coresponding callback

####2. MessageID and Async Every message contains a MessageID, which is composed by timestamp, machine name, and random numbers, it's very hard to get collision even in millions messages per second

Every message is executed asynchronously