1.1.1 • Published 3 years ago
set-sail-rpc-node v1.1.1
自定义RPC协议 Node.JS版本
通信协议
通信流程
使用:
1.引入依赖:
npm install set-sail-rpc-node@1.0.4 --save
2.RPC Client端使用(调用Java):
import RpcClient from "set-sail-rpc-node/RpcClient.mjs";
const rpcClient = new RpcClient("192.168.1.150:20883");
(async () => {
const result = await rpcClient.invoke("com.cupiday.xinvite.gateway.business.service.IHello", "sayHello", {name: "haha"});
console.log(result);
})();
3.RPC Server端使用:
import RpcServer from "set-sail-rpc-node/RpcServer.mjs";
import log from "../utils/Log4js.mjs";
import ConfigUtil from "../utils/ConfigUtil.mjs";
import {abnormalLogin} from "./OfflineEventService.mjs";
const server_config = ConfigUtil.getConfig("server_config");
class RPCService {
start() {
const rpcServer = new RpcServer(server_config.rpcServer.hostname, server_config.rpcServer.port);
rpcServer
.registry("OfflineEventService", "abnormalLogin", abnormalLogin)
.start();
log.info(`rpc server listen ${server_config.rpcServer.port}`);
}
}
export default new RPCService();