grenache-ruby-ws 0.2.2 → 0.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/README.md +131 -1
- data/examples/client.rb +1 -2
- data/examples/worker.rb +4 -6
- data/grenache-ruby-ws.gemspec +1 -1
- data/lib/grenache/websocket.rb +5 -0
- data/lib/grenache/websocket/version.rb +1 -1
- data/lib/grenache/ws.rb +1 -2
- data/logo.png +0 -0
- metadata +5 -4
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 0d8e09ec7280bce519ad8be70ff54a7c41b527d9
         | 
| 4 | 
            +
              data.tar.gz: 3a8cfee41845a3bc5c137a1b03178d229020cfda
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: d9885efe4809a77e34fab1b2ae6721d87b76025434f8f746efbff3a5c9c5dee92f45d3d946526b1e8841f3d88c39996b96378b6883f6f32a3baa0cb346773589
         | 
| 7 | 
            +
              data.tar.gz: 72a476ab7b7fc9b1c9511f41a677aad9fd08751c524e2ec0ea3286bf408bf92470ac0275e66577d89cfb31031488d3083abe6d506a19500772410fa0aefe7108
         | 
    
        data/Gemfile
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -1 +1,131 @@ | |
| 1 | 
            -
            # grenache-ruby-ws
         | 
| 1 | 
            +
            # grenache-ruby-ws
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            <img src="logo.png" width="15%" />
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Grenache is a micro-framework for connecting microservices. Its simple and optimized for performance.
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            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](https://github.com/bitfinexcom/grenache)
         | 
| 8 | 
            +
             | 
| 9 | 
            +
             - [Setup](#setup)
         | 
| 10 | 
            +
             - [Examples](#examples)
         | 
| 11 | 
            +
             - [API](#api)
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            ## Setup
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            ### Install
         | 
| 16 | 
            +
            ```
         | 
| 17 | 
            +
            gem install grenache-ruby-ws
         | 
| 18 | 
            +
            ```
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            ### Other Requirements
         | 
| 21 | 
            +
             | 
| 22 | 
            +
            Install `Grenache Grape`: https://github.com/bitfinexcom/grenache-grape:
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            ```bash
         | 
| 25 | 
            +
            npm i -g grenache-grape
         | 
| 26 | 
            +
            ```
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            ```
         | 
| 29 | 
            +
            // Start 2 Grapes
         | 
| 30 | 
            +
            grape --dp 20001 --aph 30001 --bn '127.0.0.1:20002'
         | 
| 31 | 
            +
            grape --dp 20002 --aph 40001 --bn '127.0.0.1:20001'
         | 
| 32 | 
            +
            ```
         | 
| 33 | 
            +
             | 
| 34 | 
            +
            ## Examples
         | 
| 35 | 
            +
             | 
| 36 | 
            +
            #### RPC Server / Client
         | 
| 37 | 
            +
             | 
| 38 | 
            +
            This RPC Server example announces a service called `rpc_test`
         | 
| 39 | 
            +
            on the overlay network. When a request from a client is received,
         | 
| 40 | 
            +
            it replies with `world`. It receives the payload `hello` from the
         | 
| 41 | 
            +
            client.
         | 
| 42 | 
            +
             | 
| 43 | 
            +
            The client sends `hello` and receives `world` from the server.
         | 
| 44 | 
            +
             | 
| 45 | 
            +
            Internally the DHT is asked for the IP of the server and then the
         | 
| 46 | 
            +
            request is done as Peer-to-Peer request via websockets.
         | 
| 47 | 
            +
             | 
| 48 | 
            +
            **Grape:**
         | 
| 49 | 
            +
             | 
| 50 | 
            +
            ```bash
         | 
| 51 | 
            +
            grape --dp 20001 --aph 30001 --bn '127.0.0.1:20002'
         | 
| 52 | 
            +
            grape --dp 20002 --aph 40001 --bn '127.0.0.1:20001'
         | 
| 53 | 
            +
            ```
         | 
| 54 | 
            +
             | 
| 55 | 
            +
            **Server:**
         | 
| 56 | 
            +
             | 
| 57 | 
            +
            ```rb
         | 
| 58 | 
            +
            require "grenache-ruby-ws"
         | 
| 59 | 
            +
             | 
| 60 | 
            +
            EM.run do
         | 
| 61 | 
            +
              Signal.trap("INT")  { EventMachine.stop }
         | 
| 62 | 
            +
              Signal.trap("TERM") { EventMachine.stop }
         | 
| 63 | 
            +
             | 
| 64 | 
            +
              c = Grenache::Ws.new(grape_address: "http://127.0.0.1:40001/")
         | 
| 65 | 
            +
              port = 5001
         | 
| 66 | 
            +
             | 
| 67 | 
            +
              c.listen("test_service", port) do |req|
         | 
| 68 | 
            +
                error = nil
         | 
| 69 | 
            +
                [error,"hello #{req.payload}"]
         | 
| 70 | 
            +
              end
         | 
| 71 | 
            +
            end
         | 
| 72 | 
            +
            ```
         | 
| 73 | 
            +
             | 
| 74 | 
            +
            **Client:**
         | 
| 75 | 
            +
             | 
| 76 | 
            +
            ```rb
         | 
| 77 | 
            +
            require "grenache-ruby-ws"
         | 
| 78 | 
            +
             | 
| 79 | 
            +
            c = Grenache::Ws.new(grape_address: "http://127.0.0.1:40001/")
         | 
| 80 | 
            +
             | 
| 81 | 
            +
            EM.run do
         | 
| 82 | 
            +
              10.times do |n|
         | 
| 83 | 
            +
                c.request("test_service","world #{n}") do |err, msg|
         | 
| 84 | 
            +
                  if err
         | 
| 85 | 
            +
                    puts "error: #{err}"
         | 
| 86 | 
            +
                  else
         | 
| 87 | 
            +
                    puts "response: #{msg}"
         | 
| 88 | 
            +
                  end
         | 
| 89 | 
            +
                end
         | 
| 90 | 
            +
              end
         | 
| 91 | 
            +
            end
         | 
| 92 | 
            +
             | 
| 93 | 
            +
             | 
| 94 | 
            +
            ```
         | 
| 95 | 
            +
             | 
| 96 | 
            +
            [Code Server](https://github.com/bitfinexcom/grenache-ruby-ws/blob/master/examples/worker.rb)
         | 
| 97 | 
            +
            [Code Client](https://github.com/bitfinexcom/grenache-ruby-ws/blob/master/examples/client.rb)
         | 
| 98 | 
            +
             | 
| 99 | 
            +
            ## API
         | 
| 100 | 
            +
             | 
| 101 | 
            +
            ### Class: Grenache::Ws
         | 
| 102 | 
            +
             | 
| 103 | 
            +
            ### Grenache::Ws.new(options)
         | 
| 104 | 
            +
              - `options`
         | 
| 105 | 
            +
                - `:grape_address` <String>
         | 
| 106 | 
            +
                - `:timeout` <Number>
         | 
| 107 | 
            +
             | 
| 108 | 
            +
                - `:auto_announce_interval` <Number>
         | 
| 109 | 
            +
                - `:auto_announce` <Boolean>
         | 
| 110 | 
            +
                - `:service_timeout` <Number>
         | 
| 111 | 
            +
                - `:service_host` <String>
         | 
| 112 | 
            +
             | 
| 113 | 
            +
            ### client.request(name, payload, options)
         | 
| 114 | 
            +
              - `name` <String> Name of the service to address
         | 
| 115 | 
            +
              - `payload` Payload to send
         | 
| 116 | 
            +
              - `options`
         | 
| 117 | 
            +
                - `:timeout` Timeout for the request
         | 
| 118 | 
            +
             | 
| 119 | 
            +
            Sends a single request to a RPC server/worker.
         | 
| 120 | 
            +
            [Example](https://github.com/bitfinexcom/grenache-ruby-ws/blob/master/examples/client.rb).
         | 
| 121 | 
            +
             | 
| 122 | 
            +
             | 
| 123 | 
            +
            ### client.listen(key, port, options)
         | 
| 124 | 
            +
              - `name` <String> Name of the service to announce
         | 
| 125 | 
            +
              - `port` <Number> Port to listen
         | 
| 126 | 
            +
              - `options`
         | 
| 127 | 
            +
             | 
| 128 | 
            +
            Sets up a worker which connects to the DHT.
         | 
| 129 | 
            +
            Listens on the given `port`.
         | 
| 130 | 
            +
             | 
| 131 | 
            +
            [Example](https://github.com/bitfinexcom/grenache-ruby-ws/blob/master/examples/worker.rb).
         | 
    
        data/examples/client.rb
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            require_relative '../lib/grenache-ruby-ws.rb'
         | 
| 2 2 |  | 
| 3 3 | 
             
            Grenache::Ws.configure do |conf|
         | 
| 4 | 
            -
               conf.grape_address = " | 
| 4 | 
            +
               conf.grape_address = "http://127.0.0.1:40002/"
         | 
| 5 5 | 
             
            end
         | 
| 6 6 |  | 
| 7 7 | 
             
            EM.run do
         | 
| @@ -15,5 +15,4 @@ EM.run do | |
| 15 15 | 
             
                  end
         | 
| 16 16 | 
             
                end
         | 
| 17 17 | 
             
              end
         | 
| 18 | 
            -
             | 
| 19 18 | 
             
            end
         | 
    
        data/examples/worker.rb
    CHANGED
    
    | @@ -1,16 +1,14 @@ | |
| 1 1 | 
             
            require_relative '../lib/grenache-ruby-ws.rb'
         | 
| 2 2 |  | 
| 3 | 
            -
            Grenache::Ws.configure do |conf|
         | 
| 4 | 
            -
               conf.grape_address = "ws://127.0.0.1:30001"
         | 
| 5 | 
            -
            end
         | 
| 6 | 
            -
             | 
| 7 3 | 
             
            EM.run do
         | 
| 8 4 |  | 
| 9 5 | 
             
              Signal.trap("INT")  { EventMachine.stop }
         | 
| 10 6 | 
             
              Signal.trap("TERM") { EventMachine.stop }
         | 
| 11 | 
            -
              c = Grenache::Ws.new
         | 
| 12 7 |  | 
| 13 | 
            -
              c. | 
| 8 | 
            +
              c = Grenache::Ws.new grape_address: "http://127.0.0.1:40002/"
         | 
| 9 | 
            +
              port = 5004
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              c.listen('rpc_test', port) do |req|
         | 
| 14 12 | 
             
                [nil,"hello #{req.payload}"]
         | 
| 15 13 | 
             
              end
         | 
| 16 14 |  | 
    
        data/grenache-ruby-ws.gemspec
    CHANGED
    
    | @@ -19,7 +19,7 @@ Gem::Specification.new do |spec| | |
| 19 19 |  | 
| 20 20 | 
             
              spec.add_runtime_dependency "eventmachine", "~> 1.0"
         | 
| 21 21 | 
             
              spec.add_runtime_dependency "faye-websocket", "~> 0.10"
         | 
| 22 | 
            -
              spec.add_runtime_dependency "grenache-ruby-base", "~> 0.2. | 
| 22 | 
            +
              spec.add_runtime_dependency "grenache-ruby-base", "~> 0.2.12"
         | 
| 23 23 | 
             
              spec.add_runtime_dependency "oj", "~> 2.18"
         | 
| 24 24 | 
             
              spec.add_runtime_dependency "thin", "~> 1.7"
         | 
| 25 25 |  | 
    
        data/lib/grenache/websocket.rb
    CHANGED
    
    | @@ -42,6 +42,10 @@ module Grenache | |
| 42 42 | 
             
                  @ws.send(payload)
         | 
| 43 43 | 
             
                end
         | 
| 44 44 |  | 
| 45 | 
            +
                def connected?
         | 
| 46 | 
            +
                  @connected
         | 
| 47 | 
            +
                end
         | 
| 48 | 
            +
             | 
| 45 49 | 
             
                private
         | 
| 46 50 | 
             
                def ws_connect
         | 
| 47 51 | 
             
                  @ws = Faye::WebSocket::Client.new(@uri)
         | 
| @@ -68,5 +72,6 @@ module Grenache | |
| 68 72 | 
             
                def on_close(ev)
         | 
| 69 73 | 
             
                  @connected = false
         | 
| 70 74 | 
             
                end
         | 
| 75 | 
            +
             | 
| 71 76 | 
             
              end
         | 
| 72 77 | 
             
            end
         | 
    
        data/lib/grenache/ws.rb
    CHANGED
    
    | @@ -19,9 +19,8 @@ module Grenache | |
| 19 19 | 
             
                  if service_cache[key] && service_cache[key].connected?
         | 
| 20 20 | 
             
                    service_cache[key].send json
         | 
| 21 21 | 
             
                  else
         | 
| 22 | 
            -
                    service_cache.delete(key)
         | 
| 23 22 | 
             
                    lookup key do |services|
         | 
| 24 | 
            -
                      if services.length > 0
         | 
| 23 | 
            +
                      if services && services.length > 0
         | 
| 25 24 | 
             
                        service = services.sample
         | 
| 26 25 | 
             
                        service_cache[key] = WebsocketClient.new(service, &cb)
         | 
| 27 26 | 
             
                        service_cache[key].send json
         | 
    
        data/logo.png
    ADDED
    
    | Binary file | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: grenache-ruby-ws
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.2. | 
| 4 | 
            +
              version: 0.2.12
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Bitfinex <info@bitfinex.com>
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2017- | 
| 11 | 
            +
            date: 2017-06-24 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: eventmachine
         | 
| @@ -44,14 +44,14 @@ dependencies: | |
| 44 44 | 
             
                requirements:
         | 
| 45 45 | 
             
                - - "~>"
         | 
| 46 46 | 
             
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            -
                    version: 0.2. | 
| 47 | 
            +
                    version: 0.2.12
         | 
| 48 48 | 
             
              type: :runtime
         | 
| 49 49 | 
             
              prerelease: false
         | 
| 50 50 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 51 | 
             
                requirements:
         | 
| 52 52 | 
             
                - - "~>"
         | 
| 53 53 | 
             
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            -
                    version: 0.2. | 
| 54 | 
            +
                    version: 0.2.12
         | 
| 55 55 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 56 56 | 
             
              name: oj
         | 
| 57 57 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -98,6 +98,7 @@ files: | |
| 98 98 | 
             
            - lib/grenache/websocket.rb
         | 
| 99 99 | 
             
            - lib/grenache/websocket/version.rb
         | 
| 100 100 | 
             
            - lib/grenache/ws.rb
         | 
| 101 | 
            +
            - logo.png
         | 
| 101 102 | 
             
            homepage: https://github.com/bitfinexcom/grenache-ruby-ws
         | 
| 102 103 | 
             
            licenses:
         | 
| 103 104 | 
             
            - MIT
         |