| 1 |
[](https://rubygems.org/gems/grpc/) |
| 2 |
gRPC Ruby |
| 3 |
========= |
| 4 |
|
| 5 |
A Ruby implementation of gRPC. |
| 6 |
|
| 7 |
PREREQUISITES |
| 8 |
------------- |
| 9 |
|
| 10 |
- Ruby 2.x. The gRPC API uses keyword args. |
| 11 |
|
| 12 |
INSTALLATION |
| 13 |
--------------- |
| 14 |
|
| 15 |
**Linux and Mac OS X:** |
| 16 |
|
| 17 |
```sh |
| 18 |
gem install grpc |
| 19 |
``` |
| 20 |
|
| 21 |
If using a Gemfile and you wish to pull from a git repository or GitHub, make sure to tell bundler to retrieve submodules: |
| 22 |
``` |
| 23 |
gem 'grpc', github: 'grpc/grpc', submodules: true |
| 24 |
``` |
| 25 |
|
| 26 |
BUILD FROM SOURCE |
| 27 |
--------------------- |
| 28 |
- Clone this repository |
| 29 |
|
| 30 |
- Init submodules |
| 31 |
|
| 32 |
```sh |
| 33 |
git submodule update --init |
| 34 |
``` |
| 35 |
|
| 36 |
- Install Ruby 2.x. Consider doing this with [RVM](http://rvm.io), it's a nice way of controlling |
| 37 |
the exact ruby version that's used. |
| 38 |
```sh |
| 39 |
$ command curl -sSL https://rvm.io/mpapis.asc | gpg --import - |
| 40 |
$ \curl -sSL https://get.rvm.io | bash -s stable --ruby=ruby-2 |
| 41 |
$ |
| 42 |
$ # follow the instructions to ensure that your're using the latest stable version of Ruby |
| 43 |
$ # and that the rvm command is installed |
| 44 |
``` |
| 45 |
- Make sure your run `source $HOME/.rvm/scripts/rvm` as instructed to complete the set up of RVM |
| 46 |
|
| 47 |
- Install [bundler](http://bundler.io/) |
| 48 |
``` |
| 49 |
$ gem install bundler |
| 50 |
``` |
| 51 |
|
| 52 |
- Finally, build and install the gRPC gem locally. |
| 53 |
```sh |
| 54 |
$ # from this directory |
| 55 |
$ bundle install # creates the ruby bundle, including building the grpc extension |
| 56 |
$ rake # runs the unit tests, see rake -T for other options |
| 57 |
``` |
| 58 |
|
| 59 |
DOCUMENTATION |
| 60 |
------------- |
| 61 |
- rubydoc for the gRPC gem is available online at [rubydoc][]. |
| 62 |
- the gRPC Ruby reference documentation is available online at [grpc.io][] |
| 63 |
|
| 64 |
CONTENTS |
| 65 |
-------- |
| 66 |
Directory structure is the layout for [ruby extensions][] |
| 67 |
- ext: the gRPC ruby extension |
| 68 |
- lib: the entrypoint gRPC ruby library to be used in a 'require' statement |
| 69 |
- spec: Rspec unittests |
| 70 |
- bin: example gRPC clients and servers, e.g, |
| 71 |
|
| 72 |
```ruby |
| 73 |
stub = Math::Math::Stub.new('my.test.math.server.com:8080', :this_channel_is_insecure) |
| 74 |
req = Math::DivArgs.new(dividend: 7, divisor: 3) |
| 75 |
GRPC.logger.info("div(7/3): req=#{req.inspect}") |
| 76 |
resp = stub.div(req) |
| 77 |
GRPC.logger.info("Answer: #{resp.inspect}") |
| 78 |
``` |
| 79 |
|
| 80 |
[ruby extensions]:http://guides.rubygems.org/gems-with-extensions/ |
| 81 |
[rubydoc]: http://www.rubydoc.info/gems/grpc |
| 82 |
[grpc.io]: https://grpc.io/docs/languages/ruby/quickstart |
| 83 |
[Debian jessie-backports]:http://backports.debian.org/Instructions/ |