GithubHelp home page GithubHelp logo

devis's Introduction

Devis

A microservices framework for Node.js http://devisjs.surge.sh

Build Status

Downloads Version License bitHound Overall Score

Devis is a framework for writing microservices and organizing the business logic of your app. You can break down your app into "stuff that happens", rather than focusing on data models or managing dependencies.

Devis provides:

  • pattern matching: a wonderfully flexible way to handle business requirements

  • transport independence: how messages get to the right server is not something you should have to worry about

Use this module to define commands that work by taking in some JSON, and, optionally, returning some JSON. The command to run is selected by pattern-matching on the the input JSON. There are built-in and optional sets of commands that help you build Minimum Viable Products: data storage, user management, distributed logic, caching, logging, etc. And you can define your own product by breaking it into a set of commands - "stuff that happens". That's pretty much it.

Requirements:

Remember that Devis is based on devispattern that is an addon written in c ++.

It's necessary, before using Devis to install:

  • CMake(*.msi version for windows: You must check the addition of the path for all users, And restart your computer after installation)
  • A proper C/C++ compiler toolchain of the given platform
    • Windows:
    • Unix/linux-gnu:
      • Clang or GCC
      • Ninja or Make (Ninja will be picked if both present)
      • Xcode with command line tools if you are under mac os

Install

To install, simply use npm.

npm install devis

Example:

-plugin.js:

var devis=require("devis");

devis.add({
  action: 'game',
  cmd:'play'
}, function(args,done) {

  done(null,args.name+" is playing game now");
});
devis.add({
  action: 'game',
  cmd:'pause'
}, function(args, done) {

  done(null,args.name+" pause the game");
});


module.exports = devis;

-index.js:

let devis=require("devis");
devis.act({ action: 'game', cmd: 'pause' },{name:"foo"}, function (err, result) {
  if (err) throw err;
  console.log(result);
});


devis.act({action: 'gamer', cmd: 'play' },{name:"foo"}, function (err, result) {
  if (err) throw err;
  console.log(result);
})

In this code,

The devis.add method adds a new pattern, and the function to execute whenever that pattern occurs.

The devis.act method accepts an object, and runs the command, if any, that matches.

This is a very convenient way of combining a pattern and parameter data.

Use network

Devis makes this really easy. Let's put configuration out on the network into its own process:

-core.js:

var devis=require("devis");

devis.add({
  action: 'game',
  cmd:'play'
}, function(args,done) {

  done(null,{ result: 'play' });
});
devis.add({
  action: 'game',
  cmd:'pause'
}, function(args, done) {

  done(null,{ result: 'pause' });
});

-server.js:

var devis=require("devis");
devis.use("./core")
.listen({
  host:'127.0.0.1',
  port:3030
})

alt tag

The listen method starts a web server that listens for JSON messages. When these arrive, they are submitted to the local Devis instance, and executed as actions in the normal way. The result is then returned to the client. You can use Http,Tcp,Unix Socket or Named Pipes.

The client code looks like this:

-Client.js:

var devis=require("devis")
.client({
  host:'127.0.0.1',
  port:3030,
  id:1
}).setName('client');

devis.act({ clientId:1,action: 'game', cmd: 'play' }, function (err,result) {
    if (err) throw err;
    console.log(result);
});

devis.act({clientId:1,action: 'game', cmd: 'pause' }, function (err,result) {
    if (err) throw err;
    console.log(result);
});

alt tag

On the client-side, calling devis.client() means that Devis will send any actions it cannot match locally out over the network. In this case, the configuration server will match the action: 'game', cmd: 'play' and action: 'game', cmd: 'pause' pattern and return the configuration data.

It's imperative to define a unique identifier for each Microservice consumed as client and add the ClientId when calling each remote propertie

###Other examples: we will take the previous example and add a Unix socket (UNIX or GNU/LINUX) and a Named Pipes (WINDOWS) instead of HTTP or TCP:

-Unix socket:

//server side:
devis.listen({path:'/tmp/mysoscket.sock'});
//Client side:
devis.client({id:1, path:'/tmp/mysoscket.sock'}).setName("client");

-Named pipes:

//Server side:
devis.listen({path:'\\\\\.\\pipe\\mynamedpipe'});
//Client side:
devis.client({id:1, path:'\\\\\.\\pipe\\mynamedpipe'}).setName("client");

devis's People

Contributors

ismailrei avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.