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

maestrojs

v0.1.2

Published

Maestrojs is a library for service orchestration relying on Redis for service discovery

Downloads

16

Readme

Build Status

Maestro.js

Maestro.js is a library that helps dynamically orchestrate different services using Redis. Services do not need to know any information about the service they depend on (only the name), this library will be responsible to resolve the options necessary to connect to all services and keep the service updated with the latest options.

Maestro.js goal is to be very simple to set up

Use case: You have 5 services using a cluster of redis machines for caching. You add a new redis and insert it into redis. Now all your services using that cache cluster will seamlessly update to use this new cache.

Example

var redis = require('redis');
var Maestro = require("maestrojs");

/**
 * Initialize Maestro with Redis endpoint
 */
var maestro = new Maestro("127.0.0.1", 6379); //default values

/**
 * Wait for Redis information and connect to it
 * (If another redis registers, then Maestro will automatically
 * update your application to use it)
 */
maestro.use('services.redis', function(entries) {
  var redis = redis.createClient(entries[0].endpoint);
  app.use('redis', redis);
})


/**
 * Register the interface for this service
 */
maestro.register("services.api", {
  endpoint: "198.176.45.68",
  version: 2.1,
  something: true
});

/**
 * Start the service
 * (it will only be executed after all dependencies are resolved)
 */
maestro.start(function() {
  // Start listening for requests
});

Install

npm install maestrojs

API

Maestro.use(serviceName, setupCallback)

Declare a dependency and a callback for setting up this dependency. The callback is called everytime that service is updated. (in the case of a cache cluster, if a new cache node registers, the setup callback will be run again)

maestro.use('services.queue', function(entries) {
  var queues = [], sqs;
  for (var i = 0; i < entries.length; i++) {
    sqs = new Sqs(entries[i].endpoint);
    queues.push(sqs);
  }
  app.use("queues", queues);
})

Maestro.register(serviceName_, options)

Declare a service's interface. It will automatically append the service to the list as soon as it is available. It is important that your service does not replace a service under the same name. This way you may have several nodes serving the same service. Options_ is an object containing as many attributes as desired. _(_id is a reserved attribute).

maestro.register("services.mailer", {
  endpoint: "198.167.14.1",
  supportHtml: true,
  version: 3
});

The service will be registered after the start function runs.

Maestro.start(callback)

Callback function called as soon as as all dependencies are resolved. Make sure to have all the dependencies declared before calling this function.

maestro.start(function() {
  var server = app.listen(3000);
})

You may register your service within the start callback:

maestro.start(function() {
  var server = app.listen(3000, function () {
    var host = server.address().address
    var port = server.address().port

    maestro.register("services.mailer", {
      host: host,
      port: port
    });
  })
})

Maestro.quit(callback)

Quitting allows you to automatically unregister your service and updating all services dependent on yours. Quitting will also close all connections to redis, so it won't receive more updates from other services, therefore use it only when you intend to close your service.

maestro.quit(function() {
  console.log("Service unregistered and connections closed")
});

Maestro.unregister(callback)

If you want to unregister your service but not stop listening to updates from other services. You may use Maestro.unregister, which will unregister your service and update all services dependent on it.

maestro.unregister(function() {
  console.log("Service unregistered")
});

Redis Configuration

It is important to notice that we require Redis to be configured to notify Maestro in case of key changes. You may set notify-keyspace-events "AKE" in redis.conf or start redis as ./redis-server --notify-keyspace-events AKE

TODO

  • Support Redis Sentinel (to remove SPoF)