kitoo-core

* [What Is Kitoo-Core](#about) * [How To Install](#installation) * [API](#api) * [CLI](#cli) * [Examples](#examples) * [Contributing](#contributing) * [License](#license)

Usage no npm install needed!

<script type="module">
  import kitooCore from 'https://cdn.skypack.dev/kitoo-core';
</script>

README

Kitoo-Core

What Is Kitoo-Core

kitoo-core is service based on zeronode, for creating server to server communication.

How To Install

For library usage.

npm install kitoo-core

And For kitooc-core cli usage.

npm install -g kitoo-core

API

Basic Concepts

There is two basic concepts in kitoo-core, Network and Router. Network service connects to Routers and communicates to other Network services through Routers. In other end Routers are just connecting together Ntworks. We will call Existing Network to already connected Routers an Networks. So all Routers in Existing Network mus be connected to All Networks.

Router

Network

Router Service

Router Service connects all network services to each other.

Network Service

Network Service can send and get messages from other services. Network Services can send messages to other Network Services via Router Service.

All network Services must be connected to All Router Services.

Usage Example

router.js

import {Router} from 'kitoo-core'

(async function () {
    try {
       let router = new Router({ bind: 'tcp:://127.0.0.1:3000' });
       await router.start();
       console.log('router started')
    } catch (err) {
       console.error(err) 
    }
}());

service1.js

import {Network} from 'kitoo-core'

(async function () {
    try {
        let network = new Network({name: 'foo', routers: ['tcp://127.0.0.1:3000']})
        await network.start();
        
        console.log('service1 started');
        
        network.onTick('baz', (msg) => {
            console.log('got message on baz event:', msg)
        })
    } catch (err) {
        console.error(err)
    }
}())

service2.js

import {Network} from 'kitoo-core'

(async function () {
    try {
        let network = new Network({name: 'bar', routers: ['tcp://127.0.0.1:3000']})
        await network.start();
        console.log('service2 started');
        let service1 = network.getService('foo');
        service1.tickAny('baz', 'Hi service1, I am service2.')
    } catch (err) {
        console.error(err)
    }
}())
#terminal 1
$ babel-node router.js
router started

#terminal 2
$ babel-node service1.js
service1 started
got message on baz event: Hi service1, I am service2.

#terminal 3
$ babel-node service2.js
service2 started