npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-askr

v1.1.2

Published

Stupid Simple Microservices dispatcher

Downloads

12

Readme

node-askr

npm version

Stupid Simple Microservices dispatcher

Description

Node Askr is a simple protocol that helps you to build a network of microservices that can communicate with each other.
It also allows an external Client to pass along command, listen or emit message so that the microservices can react to it.

Why

Meant to help you build distributed applications with the least amount of effort or tool (useful for prototyping and research). Meant with performance in mind, it will help you to build a network of microservices that can communicate with each other.

Current Status

For now, it only allow a simple server / client communication, with no network mapping and auto discovery but events dispatching and command sending is working. Careful if you are using this on an open network, as the keys signature process is not yet done, anyone can access your connected state currently.

Features

  • [X] Protocol for communication and command dispatching
  • [X] Simple server / client (no network mapping and auto discovery)
  • [X] Events dispatching
  • [X] Command sending (with response)
  • [X] Connected State

Roadmap

  • [] Authentication
  • [] Peer list exchange and synchronization (all nodes have the full view of the network)
  • [] Map Message dispatching
  • [] Network mapping and auto discovery
  • [] Network State Sync
  • [] Network dispatching (relay message to the right node via local mesh network)
  • [] raw-ify p2p communication and compression
  • [] Hotswapping w/ state hand-off
  • [] clusterisation via workspace

Final Goal

The final goal is that you just connect to a single point in your network, and get ability to monitor and control all your microservices from within all your authorized microservices or terminal. It would work within a workspace and handle hotswapping or new microservices joining the network to distribute the load and ensure your network stays connected without GB of bloatware.

Usage

Simple Server / Client (no network mapping and auto discovery)

In below example, we will create a simple server and client that will communicate with each other.
Server can be started (it will then emit time every seconds), stopped and asked to fetch the current time.
Client will ask for time, then start, wait 5s and stop the server.

server.js - Simulate an microservice agent that would fetch and emit info to a system.

import {Askr} from 'node-askr';

const agentNode = new Askr({
    name: 'agent'
});
agentNode.start();

function fetchTime() {
    const event = {
        type: 'FETCHED_TIME',
        payload: Date.now()
    }
    return event;
}

let interval;

function fetchAndBroadcastTime() {
    const event = fetchTime();
    console.log({event})
    agentNode.emit(event.type, event.payload);
};

function start() {
    interval = setInterval(fetchAndBroadcastTime, 1000);
}

function stop() {
    clearInterval(interval);
}

// Assign a listener to a command "start", "stop" and "fetch"
agentNode.on('start', (event) => {
    start();
});

agentNode.on('stop', (event) => {
    stop();
});

agentNode.on('fetch', async (event, peer) => {
    return fetchTime();
});

client.js - Simulate a client that would listen to the agent's event and react to it (send commands).

import { Client } from 'node-askr';

(async () => {
    const client = new Client({
        url: 'ws://localhost:8800',
    });

    await client.connect();

    const fetchCommand = await client.send('fetch');
    console.log('fetchCommand', fetchCommand);


    client.on('FETCHED_TIME', (data) => {
        console.log('FETCHED_TIME', data);
    });


    const sendCommand = await client.send('start');
    console.log('sendCommand', sendCommand);


    // wait 5 seconds
    await new Promise((resolve) => {
        setTimeout(resolve, 5000);
    });

    const stopCommand = await client.send('stop');
    console.log('stopCommand', stopCommand);
})();

Examples

See the examples folder for more examples.