Git Product home page Git Product logo

dot-ws's Introduction

dot-ws

dot-ws is a minimalist toolkit for building fast, scalable and fault tolerant microservices.

Install

npm i --save dot-ws

You can also clone this repository and make use of it yourself.

git clone https://github.com/Dvs-Bilisim/dot-ws.git
cd dot-ws
npm i
npm test

Configuration

  • host : binds server instance to this value. it's 0.0.0.0 by default.
  • pino : options for pino logger. it's { "level": "error" } by default.
  • port : start point for port assignment. it's 8000 by default.
  • timeout : request timeout. socket communication has auto recovery feature but in some cases you might want to have a timeout option.

Error Types

To have a better understanding on error types, there are a few more things to explain. A service is the name of your Service class in camel-case form and each static function in that class is called method. On client-side, you need to concatenate service name and method with delimiter as path. Default delimiter is a single dot(.). You can configure that by delimeter parameter.

  • INVALID_METHOD : Requested method doesn't exist in your service class
  • INVALID_PATH : Path parameter is not a valid string
  • INVALID_RESPONSE : Service sent an invalid response back
  • INVALID_SERVICE : Requested service doesn't exist
  • LOCKED : Clean shutdown on progress
  • MISSING_METHOD : Method is not a valid string
  • REQUEST_TIMEOUT : Request sent via socket but no response in allowed amount of time
  • SERVICE_TIMEOUT : No service found to send the request in allowed amount of time

Example Server

const Clerq = require('clerq');
const Server = require('dot-ws').Server;
const IORedis = require('ioredis');

class SampleService {
    static test(request, reply) {
        reply(request);
    }

    static async test2(request) {
        if (!request) throw new Error('invalid request');
        return request;
    }
}

const registry = new Clerq(new IORedis(), { expire: 5, pino: { level: 'error' } });
const server = new Server(registry);
server.addService(SampleService);
server.start();

Example Client

const Clerq = require('clerq');
const Client = require('dot-ws').Client;
const IORedis = require('ioredis');

const registry = new Clerq(new IORedis(), { expire: 5, pino: { level: 'error' } });
const client = new Client(registry);
client.send('sampleService.test', request, response => {
    console.log(response);
});

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.