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

zmq-json-pub

v0.1.2

Published

zmq json message publisher

Downloads

5

Readme

zmq-json-pub.js

A node.js module for publishing JSON messages via 0MQ (ZeroMQ)

Install 0MQ

On a Mac:

$ brew install zmq

To verify the installation

$ man zmq

See zeromq.org

Install zmq-json-pub in your project

$ npm init
$ npm install zmq-json-pub --save

Usage

The complete project can be found in the examples/demo folder.

This example shows how to create a simple app that publishes a heartbeat JSON message every 3 seconds. The example JSON is completely arbitrary. You can specify your own JSON format.

File: examples/demo/config.js

var config = {};
config.endpoint = "tcp://*:5431";
config.interval = 3000;    // micro seconds
module.exports = config;

File: examples/demo/index.js

"use strict";

var ZmqJsonPub = require('zmq-json-pub'),
	config = require('./config'),
	pub = new ZmqJsonPub();

pub.publish(config.endpoint);

let data = {
	type: "heartbeat",
	status: "OK",
	message: 'service is running',
	timestamp: Date.now()
}

function heartbeat() {
	data.timestamp = Date.now();
	console.log("sending heartbeat at " + new Date(data.timestamp));
	pub.send(data, function(err) {
    	if (err) {
        	console.log(err);
        	return;
    	}
	}); 
	setTimeout(heartbeat, config.interval); 
}

console.log("Sending heartbeat every " + config.interval / 1000 + " seconds")

setTimeout(heartbeat, config.interval);

/*
	Handle termination can close pub.
*/

//  terminator === the termination handler.
function terminator(sig) {
	if (typeof sig === "string") {
		console.log('%s: Received %s - terminating Node server ...',
        	Date(Date.now()), sig);
  		console.log("Closing publisher before exit");
  		pub.close();
  		process.exit(1);
	}
	console.log('%s: Node server stopped.', Date(Date.now()) );
}

//  Process on exit and signals.
process.on('exit', function() { terminator(); });

['SIGHUP', 'SIGINT', 'SIGQUIT', 'SIGILL', 'SIGTRAP', 'SIGABRT', 'SIGBUS',
 'SIGFPE', 'SIGUSR1', 'SIGSEGV', 'SIGUSR2', 'SIGPIPE', 'SIGTERM'
].forEach(function(element, index, array) {
	process.on(element, function() { terminator(element); });
});

To run:

$ node index.js

To stop press Ctrl-C.

Tests

Tests assume that mocha has been installed globally. If not execute the following:

$ npm install -g mocha

Run the tests from the projects root folder in one of the following ways:

$ mocha --recursive --timeout 20000

Or

$ npm test

Or if you feel like kickin' it old skool:

make test

Testing by Version

To run the tests for each version (currently there is only one version (v0001)):

$ mocha --timeout 5000 --recursive test/v0001/*test.js

The tests generate log files in a logs/ folder under the projects root folder.


Repo(s)


Contributing

In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.


Version History

Version 0.1.2 release notes

  • Wrapped send call in setTimeout
  • Added sendDelay property (in micro seconds)

Version 0.1.1 release notes

  • Updated example to use published module

Version 0.1.0 release notes

  • Initial release