{"id":13670934,"url":"https://github.com/MZMonster/node-thrift-service","last_synced_at":"2025-04-27T13:33:17.681Z","repository":{"id":68220102,"uuid":"52778626","full_name":"MZMonster/node-thrift-service","owner":"MZMonster","description":"use zookeeper to manage thrift service","archived":false,"fork":false,"pushed_at":"2016-03-20T10:07:00.000Z","size":57,"stargazers_count":47,"open_issues_count":0,"forks_count":6,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-13T22:11:28.382Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MZMonster.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-02-29T09:15:16.000Z","updated_at":"2023-07-15T04:44:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"b7f1cf27-7fd5-43fb-be7a-dfb245442ff0","html_url":"https://github.com/MZMonster/node-thrift-service","commit_stats":{"total_commits":32,"total_committers":2,"mean_commits":16.0,"dds":0.03125,"last_synced_commit":"9b789d979a93465f2ba7a5012635891b2c8d0c22"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MZMonster%2Fnode-thrift-service","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MZMonster%2Fnode-thrift-service/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MZMonster%2Fnode-thrift-service/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MZMonster%2Fnode-thrift-service/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MZMonster","download_url":"https://codeload.github.com/MZMonster/node-thrift-service/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250699400,"owners_count":21473219,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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-08-02T09:00:53.704Z","updated_at":"2025-04-27T13:33:12.669Z","avatar_url":"https://github.com/MZMonster.png","language":"JavaScript","readme":"# node-thrift-service\n\n`node \u003e= 4.0.0`\n\nUnlike other language, `javascript` can use `.apply` to call a `function`, so calling the remote nodejs service only need to transport `alias(of service), action(function of service, MUST BE A PROMISE/SYNC), params`. \n\nBy using `Thrift` , it support two way to use this module: \n\n1. When calling `nodejs service`, use the inner `msg.thrift`\n2. Using `use-defined.thrift`\n\nFeatures:\n\n- use redis/zookeeper to publish thrift service\n- caller search the services, using polling to manage thrift clients\n- client subscribe for new services\n\n\n\n\n**Warning: Thrift Server will listening on a port, so you need to config your Firewalls**\n\n\n\n\n\n# Install\n\n```shell\nnpm install node-thrift-service\n```\n\n\n\n# USAGE\n\n`cd test` and run `node server`, `node client`.\n\n\nThriftServer\n\n``` javascript\nconst ThriftServer = require('node-thrift-service').ThriftServer;\n\nlet server = new ThriftServer({\n    adapter: {\n    name   : 'zookeeper',\n    options: {\n      connect                 : '127.0.0.1:2181',\n      timeout                 : 200000,\n      debug_level             : ZooKeeper.ZOO_LOG_LEVEL_ERROR,\n      host_order_deterministic: false,\n      data_as_buffer          : false\n    }\n  }\n});\n\nserver.on('debug', console.log);\nserver.on('info', console.log);\nserver.on('error', console.error);\n\nserver.on('ready', (info) =\u003e {\n  console.log(info);\n\n  server.add({\n    alias  : 'lodash',\n    service: _,\n    actions: ['isString', 'no_such_action']\n  });\n}); \n\n// ThriftServer host: xx.xx.xx.xx , port: 7007\n```\n\n\n\nThriftClient\n\n``` javascript\nconst ThriftServer = require('node-thrift-service').ThriftClient;\n\nlet client = new ThriftClient({\n  adapter: {\n    name   : 'zookeeper',\n    options: {\n      connect                 : '127.0.0.1:2181',\n      timeout                 : 200000,\n      debug_level             : ZooKeeper.ZOO_LOG_LEVEL_ERROR,\n      host_order_deterministic: false,\n      data_as_buffer          : false\n    }\n  }\n});\n\nclient.on('debug', console.log);\nclient.on('info', console.log);\nclient.on('error', console.error);\n\nclient.on('ready', (info) =\u003e {\n  console.log(info);\n\n  client.call('lodash', 'isString', ['a']).then(console.log);\n  // true\n  client.call('lodash', 'no_such_action', []).catch(console.error);\n  // error\n});\n```\n\n\n\n# OPTIONS \u0026\u0026 API\n\n### ThriftServer(options)  \n\n#### inner gen-nodejs\n\n- `[options.adapter]` : optional {Object}, include:\n  - `name='zookeeper'` : {String} 'redis' or 'zookeeper'\n  - `options`={} : redis: [node_redis](https://github.com/NodeRedis/node_redis) , zookeeper: [node-zookeeper](https://github.com/yfinkelstein/node-zookeeper)\n- `[options.services]` : optional {Object|Array}, each **service** include:\n  - `[alias]` : {Function|String} unique name of each service, or use `service.name` or `service.identity`\n  - `service` : {Object} origin service object\n  - `[actions]` : {Array|String} permissions, or allow all service actions, ONLY support PROMISE/SYNC\n- `[options.thrift]` : optional {Object}, include:\n  - `[port]` : {Number} if null, thrift server bind to an unused port (default to find a unused port increasing from **7007** or from this setting, **Thrift Server will listening on this port, so you need to config your Firewalls**)\n  - `[host]` : {String} if null, use ipv4 from eth0(linux) en0(osx)\n\n#### use-defined gen-nodejs\n\n- `[options.adapter]` : optional {Object}, include:\n  - `name='zookeeper'` : {String} 'redis' or 'zookeeper'\n  - `options`={} : {Object} redis: [node_redis](https://github.com/NodeRedis/node_redis) , zookeeper: [node-zookeeper](https://github.com/yfinkelstein/node-zookeeper)\n- ``[options.thrift]` : optional {Object}, include:\n  - `[port]` : {Number} if null, thrift server bind to an unused port (default to find a unused port increasing from **7007** or from this setting, **Thrift Server will listening on this port, so you need to config your Firewalls**)\n  - `[host]` : {String} if null, use ipv4 from eth0(linux) en0(osx)\n  - `alias` : {String} alias of gen-nodejs proceesor // for search thrift server\n  - `processor` : gen-nodejs proceesor // see [server.js#L102](https://github.com/apache/thrift/blob/master/lib/nodejs/lib/thrift/server.js#L102)\n  - `handler` : gen-nodejs handler\n  - `options` : {Object} gen-nodejs options\n\n#### API\n\n- `.add(services)` : invalid with  'use-defined gen-nodejs', return {Promise|bluebird}\n  - `[alias]` : {Function|String} unique name of each service, or use `service.name` or `service.identity`\n  - `service` : {Object} origin service object\n  - `[actions]` : {Array|String} permissions, or allow all service actions, ONLY support PROMISE/SYNC\n- `.on(EVENT)` : \n  - `ready` : server initial `.on('ready', (info) =\u003e {...})`\n  - `debug` : debug log `.on('ready', (info) =\u003e {...})`\n  - `info` : info log, `.on('info', (info) =\u003e {...})`\n  - `error` : error log, `.on('info', (err) =\u003e {…})`\n- `.server()` get thrift.createServer\n- `.host()` get host\n- `.port()` get port\n\n### ThriftClient(options) :\n\n- `[options.adapter]` : optional {Object}, include:\n  - `name='zookeeper'` : {String} 'redis' or 'zookeeper'\n  - `options={}` : {Object} redis: [node_redis](https://github.com/NodeRedis/node_redis) , zookeeper: [node-zookeeper](https://github.com/yfinkelstein/node-zookeeper)\n- `[options.thrifts]` : optional {Object|Array}, if you use **user-defined.thrift**, you should give this params, each **thrift** include:\n  - `alias` {String} // for search thrift server\n  - `processor` {Object} //  gen-nodejs thrift processor\n- `.call(alias, action, params, [callback])` : use inner `msg.thrift`\n  -  `alias` {String} service alias name\n  -  `action` : {String} name of action\n  -  `params` : {Array} params of `alias.action` \n  -  return `result` with {Promise|bluebird} or `callback(err, result)`\n- `.call(alias, [callback])` : for **user-defined.thrift** return `thrift.createClient`\n  - `alias` : {String} service alias name\n  - return `client` with {Promise|bluebird} or `callback(err, client)`\n- `.on(EVENT)` : \n  - `ready` : server initial `.on('ready', (info) =\u003e {...})`\n  - `debug` : debug log `.on('ready', (info) =\u003e {...})`\n  - `info` : info log, `.on('info', (info) =\u003e {...})`\n  - `error` : error log, `.on('info', (err) =\u003e {…})`\n\n# TEST\n\n`npm test` or `make test` or `make test-cover`\n\n\n\n# LICENSE\n\nMIT","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMZMonster%2Fnode-thrift-service","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMZMonster%2Fnode-thrift-service","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMZMonster%2Fnode-thrift-service/lists"}