Skip to content

Latest commit

 

History

History
 
 

ruby

gRPC in 3 minutes (Ruby)

BACKGROUND

For this sample, we've already generated the server and client stubs from helloworld.proto.

PREREQUISITES

This requires Ruby 2.1, as the gRPC API surface uses keyword args. If you don't have that installed locally, you can use RVM to use Ruby 2.1 for testing without upgrading the version of Ruby on your whole system. RVM is also useful if you don't have the necessary privileges to update your system's Ruby.

$ # RVM installation as specified at https://rvm.io/rvm/install
$ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
$ \curl -sSL https://get.rvm.io | bash -s stable --ruby=ruby-2.1
$
$ # follow the instructions to ensure that your're using the latest stable version of Ruby
$ # and that the rvm command is installed
  • N.B Make sure your run source $HOME/.rvm/scripts/rvm as instructed to complete the set-up of RVM.

INSTALL

  • Clone this repository.

  • Download the grpc debian packages from the latest grpc release and install them.

    • Later, it will possible to install them directly using apt-get install
$ wget https://github.com/grpc/grpc/releases/download/release-0_5_0/libgrpc_0.5.0_amd64.deb
$ wget https://github.com/grpc/grpc/releases/download/release-0_5_0/libgrpc-dev_0.5.0_amd64.deb
$ sudo dpkg -i libgrpc_0.5.0_amd64.deb libgrpc-dev_0.5.0_amd64.deb
  • Use bundler to install the example package's dependencies
$ # from this directory
$ gem install bundler # if you don't already have bundler available
$ bundle install

Try it!

  • Run the server
$ # from this directory
$ bundle exec ./greeter_server.rb &
  • Run the client
$ # from this directory
$ bundle exec ./greeter_client.rb

Tutorial

You can find a more detailed tutorial in gRPC Basics: Ruby