
Security News
GitHub Actions Checkout Now Blocks Risky pull_request_target Checkouts
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.
kafu-micro
Advanced tools
#特点
#安装
npm install m-service --save
#使用
##编写服务处理函数
// dir1/file1.js
// 使用传入的console参数输出可以自动在日志里带上request id,便于跟踪一个请求在所有微服务上的日志
// 返回值如果是非null,则会把该值JSON.stringify后作为结果返回,若是promise,则等待promise的结果再返回
module.exports.f1 = (console, query, body, req, res)=>{
return {query, body, msg:'success'};
}
##普通web服务模式
按照普通的web方式的方式提供服务
// web.js
let ms = require('m-service');
ms.createApp({
services:{
port: 5500,
dir: __dirname,
names:['dir1'],
}
});
//localhost:4000/api/dir1/file1/f1?p1=1&p2=2
##微服务模式:
分三个角色
###启动三个服务角色
// s1.js
let ms = require('m-service');
ms.createApp({
centers:"http://localhost:5000/api/center", //指定服务中心,多个请用;分隔
center:{ //启动center,用于服务发现
port:5000,
dataFile:'/var/log/m-service.json',
},
proxy:{ //启动proxy,自动处理服务发现,失败重试
port:4999,
},
services:{ //启动服务
port: 5500,
dir: __dirname,
names:['dir1'],
}
});
//localhost:5500/api/dir1/file1/f1?p1=1&p2=2&直接访问微服务
//localhost:4999/api/dir1/file1/f1?p1=1&p2=2&通过代理访问微服务
//localhost:5000/api/center/register&查看在线服务
###只启动微服务
// dir2/file2.js
module.exports.f = (console, query, body)=>{
return {query, body, msg:'success'};
}
// s2.js
let ms = require('m-service');
ms.createApp({
centers:"http://localhost:5000/api/center", //指定服务中心
services:{ //启动服务
port: 5501,
dir: __dirname,
names:['dir2'],
}
});
现在可以访问代理直接访问所有微服务
localhost:4999/api/dir1/file1/f1?p1=1&p2=2&&通过代理访问微服务
localhost:4999/api/dir2/file1/f1?p1=1&p2=2&&通过代理访问微服务
##开发
git clone https://github.com/yedf/micro-service.git
cd micro-service
cnpm install
sudo cnpm install -g typescript
npm start #启动微服务的注册中心、代理、服务名称为dir1的微服务
启动另一个微服务dir2
cd example && node s2.js
##只启动服务中心或代理
// /etc/m-service.json
{
centers:"http://localhost:5000/api/center", //指定服务中心
center:{ //启动center,用于服务发现
port:5000,
dataFile:'/var/log/m-service.json', //保存当前已注册服务,重启不失效
},
proxy:{ //启动proxy,自动处理服务发现,失败重试
port:4999,
}
}
cnpm i -g m-service
m-service
FAQs
kafu micro service common
The npm package kafu-micro receives a total of 22 weekly downloads. As such, kafu-micro popularity was classified as not popular.
We found that kafu-micro demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.