{"id":19225306,"url":"https://github.com/tl-open-source/tl-ngrpc","last_synced_at":"2026-06-10T23:31:41.758Z","repository":{"id":191161075,"uuid":"670970172","full_name":"tl-open-source/tl-ngrpc","owner":"tl-open-source","description":"nodejs grpc","archived":false,"fork":false,"pushed_at":"2023-07-26T08:47:49.000Z","size":7,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-19T23:17:06.169Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tl-open-source.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-07-26T08:45:32.000Z","updated_at":"2023-08-28T09:55:22.000Z","dependencies_parsed_at":"2023-08-28T13:11:38.935Z","dependency_job_id":"a9d98264-b4e9-4116-80a1-29518cf8c906","html_url":"https://github.com/tl-open-source/tl-ngrpc","commit_stats":null,"previous_names":["tl-open-source/tl-ngrpc"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tl-open-source/tl-ngrpc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tl-open-source%2Ftl-ngrpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tl-open-source%2Ftl-ngrpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tl-open-source%2Ftl-ngrpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tl-open-source%2Ftl-ngrpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tl-open-source","download_url":"https://codeload.github.com/tl-open-source/tl-ngrpc/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tl-open-source%2Ftl-ngrpc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34175887,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-10T02:00:07.152Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T15:14:32.403Z","updated_at":"2026-06-10T23:31:41.742Z","avatar_url":"https://github.com/tl-open-source.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tl-ngrpc\n\n极简node-grpc依赖包，无关业务，只做规约， 支持两种服务端，http服务, socket服务\n\n### server\n\n实体模型 Teacher 为例, 编写proto文件\n\n```proto\n// teacher.proto\nsyntax = \"proto3\";\n\npackage api;\n\nservice Teacher {\n    rpc hello (Request) returns (Response) {}\n}\nmessage Request {\n    string message = 1;\n}   \nmessage Response {\n    string message = 1;\n}\n```\n\n**启动服务**\n\n```js\nconst TlApiRpcServer = require(\"xx/xx/TlApiRpcServer\");\nconst path = require(\"path\")\n\nconst teacherApiRpcServer = new TlApiRpcServer({\n    protoPath: path.resolve(__dirname, '../proto/api/teacher.proto'), //proto文件路径\n    protoName : \"teacher\", //proto文件名称\n    protoPackage : \"api\", //proto文件定义的package \n    protoImpl : \"Teacher\", //proto定义的实体结构\n    ip : \"127.0.0.1\", //服务监听ip\n    port : 50051 //服务监听端口\n});\n\n//启动服务端\nteacherApiRpcServer\n//监听接口事件，并定义处理逻辑\n.on(\"hello\", (call, callback) =\u003e {\n    console.log(\"服务端收到请求hello, 开始处理 : \", call.request.message);\n    callback(null, {message: 'Hello ' + call.request.message});\n})\n//监听接口事件，并定义处理逻辑\n.on(\"hello1\", (call, callback) =\u003e {\n    console.log(\"服务端收到请求hello1, 开始处理 : \", call.request.message);\n    callback(null, {message: 'Hello1 ' + call.request.message});\n})\n//启动服务\n.start();\n```\n\n\n### client\n\n```js\nconst TlApiRpcClient = require(\"../client/api/TlApiRpcClient\");\nconst path = require(\"path\")\n\nconst teacherApiRpcClient = new TlApiRpcClient({\n    protoPath: path.resolve(__dirname, '../proto/api/teacher.proto'), //proto文件路径\n    protoName : \"teacher\", //proto文件名称\n    protoPackage : \"api\", //proto文件定义的package \n    protoImpl : \"Teacher\",  //proto定义的实体结构\n    ip : \"127.0.0.1\", //服务监听ip\n    port : 50051 //服务监听端口\n});\n\n//启动客户端\n(async ()=\u003e{\n    //调用服务接口\n    let res = await teacherApiRpcClient.emit(\"hello\", {message : \"i am hello\"})\n    console.log(\"客户端收到hello结果 : \", res);\n\n    //调用服务接口\n    res = await teacherApiRpcClient.emit(\"hello1\", {message : \"i am hello1\"})\n    console.log(\"客户端收到hello1结果 : \", res);\n})()\n```\n\n#### socket服务同理，用法完全一致","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftl-open-source%2Ftl-ngrpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftl-open-source%2Ftl-ngrpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftl-open-source%2Ftl-ngrpc/lists"}