0.1.0 • Published 4 years ago

@keegpt/radonjs v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

RadonJS

An event backbone for microservices architectures using express

Version: Alpha.2

Installation

Use the package manager npm to install radonjs.

npm install @keegpt/radonjs

Server

const radon = require('../lib').default;

(() => {
    const server = new radon.Server();
})();

Clients

const radon = require('../lib').default;

(() => {
    const client = new radon.Client({
        port: 3011,
        onReady: async () => {
            await client.register();

            client.subscribe('test', async (data) => {
                console.log('3011 received:', data);
                return { success: true };
            });

            client.subscribe('another/test', async (data) => {
                console.log('3011 received:', data);
            });
        }
    });
})();
const radon = require('../lib').default;

(() => {
    const client = new radon.Client({
        port: 3012,
        onReady: async () => {
            await client.register();

            setTimeout(async () => {
                try {
                    const result = await client.get('test', { some: 'data' });
                    console.log('3012 received', result);

                    client.send('another/test', { more: 'data' });
                } catch (error) {
                    console.error(error)
                }
            }, 1000);
        }
    });
})();

Todo

Some of this are simple to do, i'm just trying to find time :(

  • Remove request-promise dependency (use native http/https)
  • Allow to customize event timeout and concurrency values
  • Create a system to get all updated stats from each event
  • A error handling system
  • A debug system
  • A microservice recovery system
  • Implement redis as core

Docs

Server options

PropertyDescription
appAn express application
pathInternal radon router path

Client options

PropertyDescription
appAn express application
hostClient host
portClient port
pathInternal radon router path
serverHostServer host
serverPortServer port
serverPathServer internal radon router path
onReadyReady to work callback

Client methods

subscribe(eventName, callback)

(() => {
    client.subscribe('EVENT_NAME', async (data: any) => {
        // logic
        // we can return data to the publisher, just returning something in this function
    });
})()

send(eventName, data)

(() => {
    client.send('EVENT_NAME', { some: 'data' });
})()

get(eventName, data)

(async () => {
    const result = await client.get('EVENT_NAME', { some: 'data' });
    console.log(result);
})()

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT