Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

frodoio

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

frodoio

Node.js library for distributing requests in a ring of servers

  • 0.9.9
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
2
Weekly downloads
 
Created
Source

Frodo.io

Build Status

Introduction

Sync your request to the same node with frodo.

Frodo.io uses etcd and hashring to provide you with a server by some key.

Simple use case: clustered database that accessed by a clustered layer that wraps it. The changes on an entity should go through the same server to prevent inconsistency.

How to use

Start with npm i frodoio --save

Simple test app that register servers and then uses them to get id would be:

  var Frodo = require('frodoio');
  var frodo = new Frodo({ context: 'appname', etcdServers: [ { host: '127.0.0.1', port: 4001 } ]});
  Q.all(frodo.addServer('dataacess1:3030'),
    frodo.addServer('dataacess2:3030'),
    frodo.addServer('dataacess3:3030')).then(function () {
      frodo.serverById(id).then(function (server) {
        request.put('http://' + server + '/entity');
      });
    });

But this application does not make any sense, because you probably want to addServer from the server and run serverById from the client.

Server:

  var Frodo = require('frodoio');
  var frodo = new Frodo({ context: 'appname', etcdServers: [ { host: '127.0.0.1', port: 4001 } ]});
  
  // http://stackoverflow.com/questions/3653065/get-local-ip-address-in-node-js
  var ip = _.chain(require('os').networkInterfaces()).flatten().filter(function(val){ return (val.family == 'IPv4' && val.internal == false) }).pluck('address').first().value(); 
  var me = ip + ':3030';
  
  function start(done) {
    frodo.addServer(me).then(done);
  }
  
  function stop(done) {
    frodo.removeServer(me).then(function () {
      frodo.close().then(done);
    });
  }

Client:

  var Frodo = require('frodoio');
  var frodo = new Frodo({ context: 'appname', etcdServers: [ { host: '127.0.0.1', port: 4001 } ]});
  frodo.serverById(function (server) {
    request.put('http://' + server + '/entity');
  });

API

Frodo constructor options

  • context - the prefix in etcd structure default value is frodo
  • etcdServers - array of servers ip and ports strings/objects or one string/object. String is only the server name and the object is { host: <host>, port: <port> }. The default port if not set is 4001, the default host if not set is localhost.
  • lazy - set to true if you wish to init later (manually)

Functions

init()

Initialze the library, this function need to be called manually only if lazy is set to true.

addServer(server, options)

Adding a server to frodo. Available options are:

  • id - Setting a specific id in addition to server key, if not set, the default is the process id.
removeServer(server, options)

Removing a server from frodo. Available options are:

  • id - Removing the server with the specific id (see addServer), if not set, the default is the process id.
  • all - Removing all servers with server key.
servers()

Getting the servers that are in frodo cache.

serverById(id)

Retrieving the server for the id, the return value is always the same if there is no change in servers list.

close()

Closing the connection to etcd.



Any comments/suggestions/pull requests would be appreciated!

License

Apache

Keywords

FAQs

Package last updated on 10 Aug 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc