GithubHelp home page GithubHelp logo

dot-microservices / dot-bee Goto Github PK

View Code? Open in Web Editor NEW
9.0 4.0 0.0 260 KB

Home Page: https://github.com/umuplus/beems

License: MIT License

JavaScript 100.00%
microservices fault-tolerance service-discovery bee-queue concurrency rpc soa microservice-framework microservice-toolkit

dot-bee's Introduction

dot-bee

a bee-queue based minimalist toolkit for building fast, decentralized, scalable and fault tolerant microservices

Motivation

major difference from other dot-rest or dot-ws projects is that it works on top of a redis-based solid message queue called bee-queue. because of that, clerq based service discovery is out of the architecture.

on the other hand, original dot has auto service discovery feature and because of its dependencies, it has completely different use cases.

Install

npm i --save dot-bee

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

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

Before running tests, please make sure that you have Redis available on localhost. If you don't know how to do that temporarily, please use following command to run it via docker.

docker run -p 6379:6379 --name dot_redis redis:4-alpine

Configuration

  • bee: options for initializing a bee queue instance. please see more details at Bee Queue Settings.
  • job: options for creating a bee queue job. only setId, retries, backoff, delayUntil and timeout methods allowed. please see more details at Bee Queue Job Settings.
  • pino: options for pino logger. it's { "level": "error" } by default.

Server Methods

  • .addServices(services, concurrency = 1, options): adds list of services and automatically creates their queues and consumers
  • .addService(service, concurrency = 1, options): adds a new service and automatically creates related queue and its consumer
  • .close(): stops all existing queues for a clean shutdown
  • .destroy(): removes everything about existing queues from redis

Client Methods

  • .acceptServices(services, options): accepts existing services to send jobs
  • .acceptService(service, options): accepts an existing service to send jobs
  • .forward(service, method, data, options): sends a new job to an existing service
  • .send(service, method, data, options): sends a new job to an existing service and retrieves its response
  • .close(): stops all existing queues for a clean shutdown

Examples

const { Client, Server } = require('dot-bee');

class Service {
    static _name() {
        return 'myService';
    }

    static async echo(job) {
        return job.data;
    }
}

const client = new Client();
const server = new Server();
server.addServices([ Service ]);
client.acceptServices([ 'myService' ]);

const r = await client.send('test', 'echo', { t: Date.now() });
console.log(r);

await client.close();
await server.destroy();
await server.close();

Optional Job Configuration

please see more details at Bee Queue Job Settings.

await client.send('test', 'echo', { t: Date.now() }, {
    setId: 'my-custom-job-id',
    retries: 2,
    backoff: [ 'fixed', 1000 ],
    delayUntil: Date.parse('2082-08-23T00:00:01.000Z'),
    timeout: 10000
});

dot-bee's People

Contributors

umuplus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

dot-bee's Issues

implement prefix for service names

Regular cases work just fine with current implementation but when it comes to separating environments like production, staging, development, testing, etc. we need a prefix for queue names those build up by using service names.

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.