{"id":41489200,"url":"https://github.com/eggjs/egg-sofa-rpc","last_synced_at":"2026-01-23T18:16:18.573Z","repository":{"id":57220750,"uuid":"136461201","full_name":"eggjs/egg-sofa-rpc","owner":"eggjs","description":"SOFARPC plugin for egg","archived":false,"fork":false,"pushed_at":"2020-06-27T07:34:58.000Z","size":17251,"stargazers_count":83,"open_issues_count":5,"forks_count":2,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-10-08T00:34:29.666Z","etag":null,"topics":["egg-plugin","eggjs","sofa-rpc","sofastack"],"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/eggjs.png","metadata":{"files":{"readme":"README.md","changelog":"History.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-07T10:28:17.000Z","updated_at":"2024-07-04T09:36:28.000Z","dependencies_parsed_at":"2022-08-28T23:23:25.047Z","dependency_job_id":null,"html_url":"https://github.com/eggjs/egg-sofa-rpc","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/eggjs/egg-sofa-rpc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-sofa-rpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-sofa-rpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-sofa-rpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-sofa-rpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eggjs","download_url":"https://codeload.github.com/eggjs/egg-sofa-rpc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-sofa-rpc/sbom","scorecard":{"id":368778,"data":{"date":"2025-08-11","repo":{"name":"github.com/eggjs/egg-sofa-rpc","commit":"82ad8495eb1f01b73b3cfda9b9318928f6c8c19b"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.9,"checks":[{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":1,"reason":"Found 2/13 approved changesets -- score normalized to 1","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":8,"reason":"binaries present in source code","details":["Warn: binary detected: test/fixtures/apps/hessian4/assembly/hessian4-facade-1.0.0-sources.jar:1","Warn: binary detected: test/fixtures/apps/hessian4/assembly/hessian4-facade-1.0.0.jar:1"],"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 10 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-18T12:29:47.809Z","repository_id":57220750,"created_at":"2025-08-18T12:29:47.810Z","updated_at":"2025-08-18T12:29:47.810Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28697428,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-23T17:25:48.045Z","status":"ssl_error","status_checked_at":"2026-01-23T17:25:47.153Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["egg-plugin","eggjs","sofa-rpc","sofastack"],"created_at":"2026-01-23T18:16:17.668Z","updated_at":"2026-01-23T18:16:18.555Z","avatar_url":"https://github.com/eggjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# egg-sofa-rpc\n\n[![NPM version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n[![Test coverage][codecov-image]][codecov-url]\n[![David deps][david-image]][david-url]\n[![Known Vulnerabilities][snyk-image]][snyk-url]\n[![npm download][download-image]][download-url]\n\n[npm-image]: https://img.shields.io/npm/v/egg-sofa-rpc.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/egg-sofa-rpc\n[travis-image]: https://img.shields.io/travis/eggjs/egg-sofa-rpc.svg?style=flat-square\n[travis-url]: https://travis-ci.org/eggjs/egg-sofa-rpc\n[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/egg-sofa-rpc.svg?style=flat-square\n[codecov-url]: https://codecov.io/github/eggjs/egg-sofa-rpc?branch=master\n[david-image]: https://img.shields.io/david/eggjs/egg-sofa-rpc.svg?style=flat-square\n[david-url]: https://david-dm.org/eggjs/egg-sofa-rpc\n[snyk-image]: https://snyk.io/test/npm/egg-sofa-rpc/badge.svg?style=flat-square\n[snyk-url]: https://snyk.io/test/npm/egg-sofa-rpc\n[download-image]: https://img.shields.io/npm/dm/egg-sofa-rpc.svg?style=flat-square\n[download-url]: https://npmjs.org/package/egg-sofa-rpc\n\n[SOFARPC](https://github.com/alipay/sofa-rpc) plugin for egg framework\n\n## Install\n\n```bash\n$ npm i egg-sofa-rpc --save\n```\n\n## Usage\n\n### Enable the plugin\n\nChange `${app_root}/config/plugin.js` to enable SOFARPC plugin:\n\n```js\nexports.sofaRpc = {\n  enable: true,\n  package: 'egg-sofa-rpc',\n};\n```\n\n### RPC Service Discovery\n\nBy default, We use zookeeper for service discovery. Therefore you need to configure the zk address:\n\n```js\n// ${app_root}/config/config.${env}.js\nconfig.rpc = {\n  registry: {\n    address: '127.0.0.1:2181', // configure your real zk address\n  },\n};\n```\n\nWe plan to provide more implementations of service discovery. And also you can implement it by yourself, you can follow this [article](https://github.com/eggjs/egg-sofa-rpc/wiki/%E8%87%AA%E5%AE%9A%E4%B9%89%E6%9C%8D%E5%8A%A1%E5%8F%91%E7%8E%B0%E5%AE%9E%E7%8E%B0)\n\n### RPC Client\n\nBy using the plugin, you can call rpc services provided by other system.\n\n#### 1. Get the RPC Interface Definition\n\nWe use [protobuf interface definition lanaguge](https://developers.google.com/protocol-buffers/docs/proto3) to describe the RPC service. So you need to get the \\*.proto files and put them into `${app_root}/proto` folder\n\n#### 2. Global RPC Client Configuration\n\nConfigure RPC Client information in ${app_root}/config/config.{env}.js:\n\n```js\n// ${app_root}config/config.${env}.js\nexports.rpc = {\n  client: {\n    responseTimeout: 3000,\n  },\n};\n```\n\n- `responseTimeout`(optional): RPC timeout in milliseconds, default value is 3000\n\n#### 3. Configure the Interface in proxy.js\n\n`${app_root}/config/proxy.js` is a very important config file for rpc client, you should configure the services you needed, then executing the `egg-rpc-generator` tool to generate the proxy files.\n\nLet's see a simple example of proxy.js. It declare a interface named: `com.alipay.sofa.rpc.test.ProtoService` provided by `sofarpc` application\n\n```js\n'use strict';\n\nmodule.exports = {\n  services: [{\n    appName: 'sofarpc',\n    api: {\n      ProtoService: 'com.alipay.sofa.rpc.test.ProtoService',\n    },\n  }],\n};\n```\n\nRefer this [acticle](https://github.com/eggjs/egg-sofa-rpc/wiki/RPC-%E4%BB%A3%E7%90%86%EF%BC%88Proxy%EF%BC%89%E9%85%8D%E7%BD%AE) for more details\n\n#### 4. Generate the Proxy\n\nRun `egg-rpc-generator` to generate the proxy files. After running success, it will generate a file: `ProtoService.js` under `${app_root}/app/proxy`\n\n```bash\n$ egg-rpc-generator\n\n[EggRpcGenerator] framework: /egg-rpc-demo/node_modules/egg, baseDir: /egg-rpc-demo\n[ProtoRPCPlugin] found \"com.alipay.sofa.rpc.test.ProtoService\" in proto file\n[ProtoRPCPlugin] save all proto info into \"/egg-rpc-demo/run/proto.json\"\n```\n\n#### 5. Call the Service\n\nYou can call the RPC service by using `ctx.proxy.proxyName`. The proxyName is `key` value of api object you configure in proxy.js. In our example, it's ProtoService, and proxyName using lower camelcase, so it's `ctx.proxy.protoService`\n\n```js\n'use strict';\n\nconst Controller = require('egg').Controller;\n\nclass HomeController extends Controller {\n  async index() {\n    const { ctx } = this;\n    const res = await ctx.proxy.protoService.echoObj({\n      name: 'gxcsoccer',\n\t    group: 'A',\n    });\n    ctx.body = res;\n  }\n}\n\nmodule.exports = HomeController;\n```\n\nAs above, you can call remote service as a local method.\n\n### RPC Server\n\nBy using the plugin, you also can publish your own RPC service to other system.\n\n#### 1. Define the RPC Interface\n\nWriting the \\*.proto files, and put them into `${app_root}/proto` folder\n\n```\n# ProtoService.proto\nsyntax = \"proto3\";\n\npackage com.alipay.sofa.rpc.protobuf;\noption java_multiple_files = true; // 可选\noption java_outer_classname = \"ProtoServiceModels\"; // 可选\n\nservice ProtoService {\n    rpc echoObj (EchoRequest) returns (EchoResponse) {}\n}\n\nmessage EchoRequest {\n    string name = 1;\n    Group group = 2;\n}\n\nmessage EchoResponse {\n    int32 code = 1;\n    string message = 2;\n}\n\nenum Group {\n    A = 0;\n    B = 1;\n}\n```\n\n#### 2. Global RPC Server Configuration\n\nConfigure RPC Server information in ${app_root}/config/config.{env}.js:\n\n```js\nmodule.exports = {\n\trpc: {\n    server: {\n      namespace: 'com.nodejs.rpc',\n    },\n\t},\n},\n```\n\n- `namespace`(required): the default namespace of all rpc service\n- `selfPublish`(optional): whether every node process publish service independent, default is true\n- `port`(optional): the TCP port will be listen on\n- `maxIdleTime`(optional): server will disconnect the socket if idle for long time\n- `responseTimeout`(optional): Number of milliseconds to wait for a response to begin arriving back from the remote system after sending a request\n- `codecType`(optional): recommended serialization method，default is protobuf\n\n#### 3. Implemenation the RPC Interface\n\nPut your implementation code under `${app_root}/app/rpc` folder\n\n```js\n// ${app_root}/app/rpc/ProtoService.js\nexports.echoObj = async function(req) {\n  return {\n    code: 200,\n    message: 'hello ' + req.name + ', you are in ' + req.group,\n  };\n};\n```\n\n#### 4. RPC Unittest in Eggjs\n\n```js\n'use strict';\n\nconst mm = require('egg-mock');\n\ndescribe('test/index.test.js', () =\u003e {\n  let app;\n  before(async function() {\n    app = mm.app({\n      baseDir: 'apps/rpcserver',\n    });\n    await app.ready();\n  });\n  after(async function() {\n    await app.close();\n  });\n\n  it('should invoke HelloService', done =\u003e {\n    app.rpcRequest('com.alipay.nodejs.HelloService')\n      .invoke('hello')\n      .send([ 'gxcsoccer' ])\n      .expect('hello gxcsoccer', done);\n  });\n});\n```\n\nFor more details of `app.rpcRequest`, you can refer to this [acticle](https://github.com/eggjs/egg-sofa-rpc/wiki/%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95-RPC-%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%96%B9%E6%B3%95)\n\n## Docs\n\n- [RPC in Nodejs Part One](https://github.com/alipay/sofa-rpc-node/wiki/%E8%81%8A%E8%81%8A-Nodejs-RPC%EF%BC%88%E4%B8%80%EF%BC%89)\n- [Cross-Language Interoperability between Eggjs \u0026 SOFA](https://github.com/eggjs/egg-sofa-rpc/wiki/Eggjs-%E5%92%8C-SOFA-%E7%9A%84%E8%B7%A8%E8%AF%AD%E8%A8%80%E4%BA%92%E8%B0%83)\n- [Custom Service Discovery in Eggjs](https://github.com/eggjs/egg-sofa-rpc/wiki/%E8%87%AA%E5%AE%9A%E4%B9%89%E6%9C%8D%E5%8A%A1%E5%8F%91%E7%8E%B0%E5%AE%9E%E7%8E%B0)\n- [RPC Proxy Configuration in Eggjs](https://github.com/eggjs/egg-sofa-rpc/wiki/RPC-%E4%BB%A3%E7%90%86%EF%BC%88Proxy%EF%BC%89%E9%85%8D%E7%BD%AE)\n- [RPC Unittest in Eggjs](https://github.com/eggjs/egg-sofa-rpc/wiki/%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95-RPC-%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%96%B9%E6%B3%95)\n\n## How to Contribute\n\nPlease let us know how can we help. Do check out [issues](https://github.com/eggjs/egg/issues) for bug reports or suggestions first.\n\nTo become a contributor, please follow our [contributing guide](https://github.com/eggjs/egg/blob/master/CONTRIBUTING.md).\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feggjs%2Fegg-sofa-rpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feggjs%2Fegg-sofa-rpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feggjs%2Fegg-sofa-rpc/lists"}