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

tcppubsub

v1.0.6

Published

A simple node-js-tcp publish-subscribe framework. With a broker and a client called member.

Downloads

26

Readme

tcppubsub

A simple and lightweight submarine build with publish-subscribe-request-response-methods. With a broker called broker :octopus: and a client called member :dolphin:.

Logo

A simple and fast exchange of data between nodejs-apps. Use the publish-subscribe-pattern to handle events or use the request-response-pattern to query or serve some data. Otherwise, get into a submarine and look for the octopus.

Build Status

Installing

npm i tcppubsub

Broker :octopus:

A broker handles all data from the members, like sockets, topics and payload. You can use some events to handle the member-data directly at the broker-side.

Example

var tcppubsub = require('tcppubsub')

var port = 2223
var host = 'localhost'
var block = true // block payload sending to publisher, if he has subscribed the topic too. Default: true (blocked)

var broker = new tcppubsub.Broker(port, host, block)
broker.listen() 

broker.getConnections(function(err, numb){
    console.log('connected members:', numb)
})

// Publish on topics from broker
broker.pub('hey/ho', 'Yellow submarine!')

//use the socket-events like:
broker.on('end', function(msg){console.log('end:', msg)})
broker.on('close', function(member){console.log('close:', msg)})
broker.on('error', function(err){console.log('error:', err)})
broker.on('published', function(data){console.log('published:', data)})
broker.on('subscribed', function(topic){console.log('subscribed:', topic)})
broker.on('unsubscribed', function(topic){console.log('unsubscribed:', topic)})

Member :dolphin:

  • Publish-subscribe data.
  • Listen on requests.
  • Query some data from listeners.
  • Topic without wildcard 'app/configuration/server' .
  • Topic with wildcard 'app/configuration/#' or 'app/#/configuration',....
  • Data can be a string or a object and is emitted as a buffer.
  • When the broker restarting, it will automatically resubscribe all topics from subscription or listeners.

Connect

Call the connect-method to connect the member.

member.connect(function(){
    // Use other methods like sub, unsub, pub, req, listen in here.
})

Subscribe

Subscribe a topic. For multiple topics give a array of topics like ['topic1', 'topic2',...].

member.sub(topic, function(topic){})

Unsubscribe

Unsubscribe a topic. For multiple topics give a array of topics like ['topic1', 'topic2',...].

member.unsub(topic)

Publish

Publish some data on a topic.

member.pub(topic, data)

Request

Make a request on a listener topic. Set some timeout in ms for handle timeout-errors. Default-timeout: 10min.

member.req(topic, data, function(err, data, id){
    if(err){
        console.log(err) // timeout error
    }else{
        console.log(data)
    }
}, timeout)

Listen

Listen on a specific topic for requests. Handle the data and send the response with res.

member.listen(topic, function(data, res){
    console.log(data)
    res(data)
})

Message Event

Catch a message-event with namespace message for receiving all messages or use a specific topic.

member.on('my/super/topic', function(data){
    // data on the certain topic
})

/******* OR *******/

member.on('message', function(topic, data){
    // all data
})

Example

var tcppubsub = require('tcppubsub')

var port = 2223
var host = 'localhost'

//Create the member
var member = new tcppubsub.Member(port, host)


member.connect(function(){

    //Subscribe the topic without callback
    member.sub('app/configuration/service')

    // Subscribe the topic STRING or ARRAY
    member.sub('app/configuration/server', function(topic){

        // Publish some data STRING, OBJECT, ARRAY
        member.pub('app/configuration/server', {name: 'yamigr', b : 'Hello World'})
    })


    // Receive the data on the certain topic
    member.on('app/configuration/server', function(data){

        // Unsubscribe the topic
        member.unsub('app/configuration/server')
        console.log('rcv publish:', data)
    })

    /******* OR *******/

    // Receive all publishes on subscribed data
    member.on('message', function(topic, data){
        member.unsub('app/configuration/server')
        console.log(topic, data)
    })


    member.listen('app/static/config', function(data, res){
        res({ msg: 'Hello ' + data.name})
    })


    let timeout = 2000 // default 5000

    member.req('app/static/config', { name : 'Peter Pan'}, function(err, data, id){
        if(!err){
            console.log('rcv response:', data.msg)
        }
    }, timeout)
})


Authors

ToDo

  • Benchmark tests (broker and members)

License

This project is licensed under the MIT License - see the LICENSE.md file for details