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

merkury

v1.3.0

Published

transparent multi instance event-emitter using redis

Downloads

10

Readme

merkury

Build Status license 5cf

  • merkury ~ mercury => hermes
  • battle tested
  • test coverage 80%+
  • 100% promise api
  • super simple .on() and .emit() EventEmitter API
  • lightweight and fast
    npm install --save merkury

how does it help?

  • (if got more time -> check "use case?" below)
  • before you implement some sort of database polling, check out merkury
  • just setup an instance of mercury in each service instance with the same topic name and redis configuration
  • listen for your event mk.on("my-event",..);
  • whenever you receive information and need to update other instances just call mk.emit("my-event",..); on one of your instances and every single one will receive the update

simple api usage

    const Merkury = require("merkury");
    
    const ioRedisConfig = {
        host: "localhost",
        port: 6379
    };
    
    const mk = new Merkury("unique-service-name", ioRedisConfig, true);
    
    //super easy API just like the usual event-emitter:
    
    mk.on("my-event", (arg1, arg2, arg3) => { .. });
    mk.emit("my-event", "arg1", {}, "arg3");
    
    //some advanced sugar available:
    
    mk.disconnect().then(_ => { .. });
    mk.setConfig() / mk.setTopic();
    mk.connect().then(_ => { .. }); //reconnect with topic switch
    
    mk.pause();
    mk.resume() //pause & resume handler
    
    //subscribe to error events
    mk.on("error", err => { .. });

event race-lock mode


    mk1.on("my-event", arg1 => { console.write(arg1) });
    mk2.on("my-event", arg1 => { console.write(arg1) });
    mk3.on("my-event", arg1 => { console.write(arg1) });

    mk1.on("my-race-event", arg1 => { console.write(arg1) }, true);
    mk2.on("my-race-event", arg1 => { console.write(arg1) }, true);
    mk3.on("my-race-event", arg1 => { console.write(arg1) }, true);
    
    //with race mode disabled (usually)
    mk1.emit("my-event", 1); //output: 1\n1\n1\n
    
    //with race mode enabled
    mk1.emit("my-race-event", 1, 2, 3); //output: 1\n
    
    //race mode uses "redlock" algorithm to ensure only a single
    //Merkury{} instance will call its EventListener
    //merkury takes track of its race enabled events and is able
    //to remove them permanently when using e.g. mk1.removeListener(..)

use-case?

  • imagine a world full of microservices
  • imagine you need high availabilty
  • the first thing you will do is scale your microservices to multiple instances or containers
  • imagine your instances run behind a load-balancer
  • your service/code will now only receive requests on single instances but you might need to do something with the received information on every instance - you have to notify all your instances about the updated information
  • you could implement some sort of polling..but what if you could simply notify the other instances? and what if that was just as easy as emitting a simple event