kitoo-core
v1.1.22
Published
* [What Is Kitoo-Core](#about) * [How To Install](#installation) * [API](#api) * [CLI](#cli) * [Examples](#examples) * [Contributing](#contributing) * [License](#license)
Downloads
69
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
- new Router()
- router.start()
- router.stop()
- router.connectExistingNetwork()
- router.defineLoadBalancingStrategy()
- router.tickToService()
- router.tickAnyService()
- router.tickAllServices()
- router.requestToService()
- router.requestAnyService()
- router.onTick()
- router.offTick()
- router.onRequest()
- router.offRequest()
Network
- new Network()
- router.start()
- router.stop()
- router.connectRouter()
- router.disconnectRouter()
- router.addRouter()
- router.removeRouter()
- router.proxyTick()
- router.proxyTickAny()
- router.proxyTickAll()
- router.proxyRequestAny()
- router.proxyRequest()
- router.tickToRouter()
- router.tickAnyRouter()
- router.tickAllRouters()
- router.requestToRouter()
- router.requestAnyRouter()
- router.onTick()
- router.offTick()
- router.onRequest()
- router.offRequest()
- router.subscribe()
- router.publish()
- router.getRoutingInterface()
- router.getService()
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