Thrifty::Bunny
A RabbitMQ-ApacheThrift adapter for RPC calls
Acknowledgements
This gem is largely-based on the Stephen Henrie's Apache Thrift AMQP. Thanks to Stephen for his work and excellent tutorial.
Installation
Add this line to your application's Gemfile:
gem 'thrifty-bunny'
And then execute:
$ bundle
Or install it yourself as:
$ gem install thrifty-bunny
Usage
The gem provides a Thrift server that integrates with RabbitMQ. You would use this server in standard Thrift fashion:
handler = MyHandler.new
processor = MyProcessor.new(handler)
service = ThriftyBunny::RpcServer.new(processor)
service.serve
Then you would utilize the included ClientTransport to connect your Thrift client to RabbitMQ:
transport = ThriftyBunny::ClientTransport.new
protocol = Thrift::BinaryProtocol.new(transport)
client = MyService::Client.new(protocol)
client.my_remote_method() # Make the remote procedure call
Configuration
Both the RpcServer and the ClientTransport accept a ThriftyBunny::Config object that encapsulates the RabbitMQ configuration settings. The default values for the configuration options are:
| option | value | notes |
|---|---|---|
| host | 127.0.0.1 | Host name or IP for the RabbitMQ host |
| port | 5672 | Port that RabbitMQ is listening on |
| vhost | / | Virtual host path |
| user | guest | RabbitMQ user |
| password | guest | RabbitMQ password |
| queue | rpc_queue | Name of RabbitMQ queue for the RPC messages |
| exchange | rpc_exchange | Name of the RabbitMQ exchange for the RPC messages |
Examples
An easy way to experiment with the gem is to take a look at the provided examples. There is an example simple client and server. To run the example:
Start up RabbitMQ -- it should be running on the default port (5672) with the default credentials.
Start up two separate terminals
Change to the
examplesdirectory in each terminal:$ cd examplesIn one terminal, start the server:
$ bundle exec bin/server.startIn the other terminal, start the client:
$ bundle exec bin/client.startIn the RabbitMQ admin console, you can monitor the message queues.
The client prompts you to enter a name, then the servers respond by saying hello to you. Feel free to start up additional servers to demonstrate how the system scales.
Contributing
- Fork it ( https://github.com/[my-github-username]/thrifty-bunny/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request