2.0.0 • Published 10 days ago

micro-serves v2.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
10 days ago

简易微服务库

基于tcp或者udp连接

2.0.0 入参有变化,并且修复重大Bug

tcp支持集群

import cluster from 'cluster'
import {cpus} from 'os'

if (cluster.isPrimary) {

    cpus().forEach(() => cluster.fork())

} else {

    // todo

    console.log(`Worker ${process.pid} started`)
}

udp

import {udpService, tcpService} from './index.mjs'
const pools = {
    s: {test: 'localhost:9000/test'}
}
// 9000端
const s = udpService(pools, {port: 9000}, function (path, data, next) {

    next('9000')
})
// s.close()
// 9001端
const map = new Map
map.set('/test', data => new Promise((resolve, reject) => reject('9001')))
udpService(pools, {port: 9001}, map).s.test().then(r => console.log(r.toString())) // '9000'

tcp

const pools = {
    s: {test: 'localhost:9000/test'}
}
// 9000端
const map = new Map
map.set('/test', data => '9000')
const s = tcpService(pools, {port: 9000}, map)
// s.close()
// 9001端
tcpService(pools, {port: 9001}, function (path, data, next) {})
    .s.test().then(r => assert.equal(r, '9000')) // '9000'

实例文件test.mjs

2.0.0

10 days ago

1.0.0

1 month ago

0.9.0

8 months ago

0.8.2

1 year ago

0.8.1

2 years ago

0.8.0

2 years ago