Giter Site home page Giter Site logo

zeromq's Introduction

Zeromq implementations in Typescript

Build Status

Patterns

  • Dealer-Router (Brokerless Paranoid Pirate)
  • Req-Rep
  • Pub-Sub
  • Pull-Push

Features

  • Automatic workers health-check
  • Retry strategy
  • Load balancing
  • async/await
  • Tracing (Zipkin integration)

Protocol

export type Request = {
    body?: Body,
    headers?: Headers,
    path: Path,
};
export type Response = {
    body?: Body,
    code: Code,
    headers?: Headers,
};

Dealer architecture

delaer router

Usage

Boot the server:

import Router from "../src/Transport/Patterns/Dealer-Router/Router";
import {BatchRecorder, Tracer} from "zipkin";
import CLSContext from "zipkin-context-cls";
import {HttpLogger} from "zipkin-transport-http";
import * as zipkin from "zipkin";
import JSON_V2 = zipkin.jsonEncoder.JSON_V2;

const server: Router = new Router(
    "tcp://127.0.0.1:3000",
    "router",
    {},
    new Tracer({
        ctxImpl: new CLSContext('zipkin'),
        recorder: new BatchRecorder({
            logger: new HttpLogger({
                endpoint: 'http://localhost:9411/api/v2/spans',
                jsonEncoder: JSON_V2
            })
        }),
        localServiceName: 'customWorker',
    }),
    'customServer'
);

server.start(() => (
    {
        body: {
            res: "ok",
            worker: process.pid,
        },
        code: 0,
    }
));

Connect with the client:

import Dealer from "../src/Transport/Patterns/Dealer-Router/Dealer";
import {BatchRecorder, Tracer} from "zipkin";
import {HttpLogger} from "zipkin-transport-http";
import * as zipkin from "zipkin";
import JSON_V2 = zipkin.jsonEncoder.JSON_V2;
import CLSContext from "zipkin-context-cls"
import {Response} from "../src/Message/Response";

const cli: Dealer = new Dealer(
    [
        "tcp://127.0.0.1:3000",
        "tcp://127.0.0.1:3001",
    ],
    {},
    3,
    3000,
    new Tracer({
        ctxImpl: new CLSContext('zipkin'),
        recorder: new BatchRecorder({
            logger: new HttpLogger({
                endpoint: 'http://localhost:9411/api/v2/spans',
                jsonEncoder: JSON_V2
            })
        }),
        localServiceName: 'client'
    })
);

void (async () => {
    await cli.start();

    try {
        const response: Response = await cli.request({
            body: { wut: "????" },
            path: "ping",
        }, 100);

        console.log(response);

    } catch (e) {
        console.log(e.message);
    }
})();

Result:

tracing-dash tracing-cli tracing-server

zeromq's People

Contributors

dependabot[bot] avatar jorge07 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  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.