{"id":22608941,"url":"https://github.com/bitfinexcom/grenache-ruby-ws","last_synced_at":"2025-08-02T04:04:35.517Z","repository":{"id":56875288,"uuid":"58453346","full_name":"bitfinexcom/grenache-ruby-ws","owner":"bitfinexcom","description":null,"archived":false,"fork":false,"pushed_at":"2017-06-24T10:13:30.000Z","size":44,"stargazers_count":3,"open_issues_count":0,"forks_count":6,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-07-14T23:07:23.290Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","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/bitfinexcom.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}},"created_at":"2016-05-10T10:49:49.000Z","updated_at":"2022-08-01T05:57:47.000Z","dependencies_parsed_at":"2022-08-20T10:40:35.695Z","dependency_job_id":null,"html_url":"https://github.com/bitfinexcom/grenache-ruby-ws","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bitfinexcom/grenache-ruby-ws","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitfinexcom%2Fgrenache-ruby-ws","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitfinexcom%2Fgrenache-ruby-ws/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitfinexcom%2Fgrenache-ruby-ws/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitfinexcom%2Fgrenache-ruby-ws/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bitfinexcom","download_url":"https://codeload.github.com/bitfinexcom/grenache-ruby-ws/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitfinexcom%2Fgrenache-ruby-ws/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267419191,"owners_count":24084115,"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","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"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-12-08T15:10:10.250Z","updated_at":"2025-08-02T04:04:35.466Z","avatar_url":"https://github.com/bitfinexcom.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# grenache-ruby-ws\n\n\u003cimg src=\"logo.png\" width=\"15%\" /\u003e\n\nGrenache is a micro-framework for connecting microservices. Its simple and optimized for performance.\n\nInternally, 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](https://github.com/bitfinexcom/grenache)\n\n - [Setup](#setup)\n - [Examples](#examples)\n - [API](#api)\n\n## Setup\n\n### Install\n```\ngem install grenache-ruby-ws\n```\n\n### Other Requirements\n\nInstall `Grenache Grape`: https://github.com/bitfinexcom/grenache-grape:\n\n```bash\nnpm i -g grenache-grape\n```\n\n```\n// Start 2 Grapes\ngrape --dp 20001 --aph 30001 --bn '127.0.0.1:20002'\ngrape --dp 20002 --aph 40001 --bn '127.0.0.1:20001'\n```\n\n## Examples\n\n#### RPC Server / Client\n\nThis RPC Server example announces a service called `rpc_test`\non the overlay network. When a request from a client is received,\nit replies with `world`. It receives the payload `hello` from the\nclient.\n\nThe client sends `hello` and receives `world` from the server.\n\nInternally the DHT is asked for the IP of the server and then the\nrequest is done as Peer-to-Peer request via websockets.\n\n**Grape:**\n\n```bash\ngrape --dp 20001 --aph 30001 --bn '127.0.0.1:20002'\ngrape --dp 20002 --aph 40001 --bn '127.0.0.1:20001'\n```\n\n**Server:**\n\n```rb\nrequire \"grenache-ruby-ws\"\n\nEM.run do\n  Signal.trap(\"INT\")  { EventMachine.stop }\n  Signal.trap(\"TERM\") { EventMachine.stop }\n\n  c = Grenache::Ws.new(grape_address: \"http://127.0.0.1:40001/\")\n  port = 5001\n\n  c.listen(\"test_service\", port) do |req|\n    error = nil\n    [error,\"hello #{req.payload}\"]\n  end\nend\n```\n\n**Client:**\n\n```rb\nrequire \"grenache-ruby-ws\"\n\nc = Grenache::Ws.new(grape_address: \"http://127.0.0.1:40001/\")\n\nEM.run do\n  10.times do |n|\n    c.request(\"test_service\",\"world #{n}\") do |err, msg|\n      if err\n        puts \"error: #{err}\"\n      else\n        puts \"response: #{msg}\"\n      end\n    end\n  end\nend\n\n\n```\n\n[Code Server](https://github.com/bitfinexcom/grenache-ruby-ws/blob/master/examples/worker.rb)\n[Code Client](https://github.com/bitfinexcom/grenache-ruby-ws/blob/master/examples/client.rb)\n\n## API\n\n### Class: Grenache::Ws\n\n### Grenache::Ws.new(options)\n  - `options`\n    - `:grape_address` \u0026lt;String\u0026gt;\n    - `:timeout` \u0026lt;Number\u0026gt;\n\n    - `:auto_announce_interval` \u0026lt;Number\u0026gt;\n    - `:auto_announce` \u0026lt;Boolean\u0026gt;\n    - `:service_timeout` \u0026lt;Number\u0026gt;\n    - `:service_host` \u0026lt;String\u0026gt;\n\n### client.request(name, payload, options)\n  - `name` \u0026lt;String\u0026gt; Name of the service to address\n  - `payload` Payload to send\n  - `options`\n    - `:timeout` Timeout for the request\n\nSends a single request to a RPC server/worker.\n[Example](https://github.com/bitfinexcom/grenache-ruby-ws/blob/master/examples/client.rb).\n\n\n### client.listen(key, port, options)\n  - `name` \u0026lt;String\u0026gt; Name of the service to announce\n  - `port` \u0026lt;Number\u0026gt; Port to listen\n  - `options`\n\nSets up a worker which connects to the DHT.\nListens on the given `port`.\n\n[Example](https://github.com/bitfinexcom/grenache-ruby-ws/blob/master/examples/worker.rb).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitfinexcom%2Fgrenache-ruby-ws","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbitfinexcom%2Fgrenache-ruby-ws","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitfinexcom%2Fgrenache-ruby-ws/lists"}