0.0
No commit activity in last 3 years
No release in over 3 years
A simple rabbitmq rpc server/client library built on bunny with message serialization using json
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.10
~> 10.4

Runtime

~> 1.7
 Project Readme

easy_bunny_rpc

Gem Version

Generic RPC client/worker library handling data serialization built on top of bunny.

Example usage

The worker. Please note the :bunny key Hash is directly fed to Bunny.new:

options = {
  queue: 'echo',
  bunny: {
    user: 'user',
    password: 'secret',
    host: 'localhost'
  }
}

worker = EasyBunnyRPC::Worker.new(options)
worker.subscribe do |payload|
  publish_success(payload) # Send a success message to the client
  # publish_failure(payload) # Send a failure message to the client
end

The client:

# initialization options
options = {
  queue: 'echo',
  bunny: {
    user: 'user',
    password: 'secret',
    host: 'localhost'
  }
}

client = EasyBunnyRPC::Client.new(options)

# timeout in seconds, default is 5
client.set_timeout(2)

# The first argument is the payload. The payload can be anything, just keep in
# mind it must be serializable to a String because .to_json is called on it
# 
# The second argument is the correlation_id.
# The correlation_id is always send back as-is by the worker.
# This way you can correlate the replies with your requests.
client.publish('hi there', 'call 1')
client.publish('hi there again', 'call 2')

# Pop will raise a ::Timeout::Error when a timeout occurs and no message is received
puts client.pop
puts client.pop

client.close

Output:

{"success"=>true, "payload"=>"hi there", "correlation_id"=>"call 1"}
{"success"=>true, "payload"=>"hi there again", "correlation_id"=>"call 2"}

Notes

  • Tested with RabbitMQ
  • Uses the expiration feature of RabbitMQ to expire messages sent by the client

Install

$ gem install easy_bunny_rpc

Author

Tom van Leeuwen, @tvl2386