grenache-grape

中文文档
2.0.0发布于 2026/11/04Apache-2.0CommonJS

Grenache Grape - DHT for micro-services

原始使用文档
文档目录9 节
  1. Install
  2. Run in Binary Mode
  3. Integrate in your Code
  4. API
  5. Class: Grape
  6. Implementations
  7. Node.JS Clients
  8. Ruby Clients
  9. CLI Clients

Grenache Grape implementation

Grenache is a micro-framework for connecting microservices. Its simple and optimized for performance.

Internally, Grenache uses Distributed Hash Tables (DHT, known from Bittorrent) for Peer to Peer connections. You can find more details how Grenche internally works at the Main Project Homepage.

Grapes are the backbone of Grenache. They manage the DHT, the base of our virtual network.

Install

// Install global (run binary)
npm install -g grenache-grape
// Install locally to project (programmatic approach)
npm install --save grenache-grape

Run in Binary Mode

grape --help

Usage: grape --dp <dht-port> --aph <http-api-port> --bn <nodes> [--b
bind-to-address]

Options:
  -b, --bind                 Listening host                             [string]
  --dp, --dht_port           DHT listening port              [number] [required]
  --dc, --dht_concurrency    DHT concurrency                            [number]
  --dht_maxTables            DHT max tables                             [number]
  --dht_maxValues            DHT max values                             [number]
  --bn, --bootstrap          Bootstrap nodes                 [string] [required]
  --aph, --api_port          HTTP api port                   [number] [required]
  --dht_peer_maxAge, --dpa   Max age for peers in DHT                   [number]
  --cache_maxAge             Maximum cache age                          [number]
  --dnl, --dht_nodeLiveness  Interval in ms to check for dead nodes     [number]
  --check_maxPayloadSize     Limit for max payload size                 [number]
  --help                     Show help                                 [boolean]
  --version                  Show version number                       [boolean]
// Run 3 Grapes
grape -b 127.0.0.1 --dp 20001 --dc 32 --aph 30001 --bn '127.0.0.1:20002,127.0.0.1:20003'
grape --dp 20002 --aph 40001 --dc 32 --bn '127.0.0.1:20001,127.0.0.1:20003'
grape --dp 20003 --aph 50001 --dc 32 --bn '127.0.0.1:20001,127.0.0.1:20002'

Integrate in your Code

const Grape = require('grenache-grape').Grape

const g = new Grape({
  // host: '127.0.0.1', // if undefined the Grape binds all interfaces
  dht_port: 20001,
  dht_bootstrap: [
    '127.0.0.1:20002'
  ],
  api_port: 30001
})

g.start()

API

Class: Grape

new Grape(options)

  • options <Object> Options for the link
    • host <String> IP to bind to. If null, Grape binds to all interfaces
    • dht_maxTables <Number> Maximum number of DHT tables
    • dht_maxValues <Number> Maximum number of DHT values
    • dht_port <Number> Port for DHT
    • dht_concurrency <Number> Concurrency for DHT
    • dht_bootstrap: <Array> Bootstrap servers
    • dht_peer_maxAge <Number> maxAge for DHT peers
    • api_port <Number> Grenache API HTTP Port

Event: 'ready'

Emitted when the DHT is fully bootstrapped.

Event: 'listening'

Emitted when the DHT is listening.

Event: 'peer'

Emitted when a potential peer is found.

Event: 'node'

Emitted when the DHT finds a new node.

Event: 'warning'

Emitted when a peer announces itself in order to be stored in the DHT.

Event: 'announce'

Emitted when a peer announces itself in order to be stored in the DHT.

Implementations

Node.JS Clients

  • https://github.com/bitfinexcom/grenache-nodejs-ws: WebSocket based Grape microservices
  • https://github.com/bitfinexcom/grenache-nodejs-http: HTTP based Grape microservices
  • https://github.com/bitfinexcom/grenache-nodejs-zmq: ZeroMQ based Grape microservices

Ruby Clients

  • https://github.com/bitfinexcom/grenache-ruby-ws: WebSocket based Grape microservices
  • https://github.com/bitfinexcom/grenache-ruby-http: HTTP based Grape microservices

CLI Clients

  • https://github.com/bitfinexcom/grenache-cli: Command Line Interface for Grape microservices

版本与发布记录

grenache-grape 共发布 48 个版本,首次发布于 2016/04/03;过去 12 个月发布了 1 个版本。

版本发布日期距今
2.0.0latest2026/11/04今天
1.0.02025/05/231.4 年前
0.9.122023/03/183 年前
0.9.112021/11/184 年前
0.9.102018/10/138 年前
0.9.92018/09/308 年前

关于 grenache-grape 的常见问题

grenache-grape 是什么?

歌海娜葡萄- DHT微服务

如何安装 grenache-grape?

在项目目录运行 npm install grenache-grape,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 grape,可以用 npx grape 直接运行。

grenache-grape 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/grenache-grape 是否存在。

grenache-grape 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

grenache-grape 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

grenache-grape 可以商用吗?

grenache-grape 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

grenache-grape 还在维护吗?

最新版本 2.0.0 发布于 2026/11/04(今天);至今共发布 48 个版本,其中过去 12 个月发布了 1 个;首次发布于 2016/04/03。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。