How-to use RabbitMQ in your Ruby applications
The anynines PaaS provides service credentials to your running applications via environment variables. We created the a9s_rabbitmq gem to simplify RabbitMQ configuration within your Ruby application. It supports generating credentials for the amqp and the bunny gem out of the box.
Usage instructions
Gemfile
You have to include the a9s_rabbitmq gem in your Gemfile:
$ gem ‘a9s_rabbitmq’
amqp gem credentials
Use the utility class to retrieve an amqp compatible configuration hash:
AMQP.start(Anynines::RabbitMQ::Utility.amqp_hash) do |connection| (…) end
or
connection = AMQP.connect(Anynines::RabbitMQ::Utility.amqp_hash)
bunny gem credentials
The a9s_rabbitmq gem also supports generating bunny compatible configuration hashes:
conn = Bunny.new(Anynines::RabbitMQ::Utility.bunny_hash)
other gems
If you would like to use another RabbitMQ client, you are able to retrieve a credentials hash containing all necessary connection information like this:
credentials_hash = Anynines::RabbitMQ::Utility.credentials_hash
This is an example of a retrieved hash:
{ :name=> "db_name", :hostname=>"10.12.0.10", :host=>"10.12.0.10", :port=>15012, :admin_port=>25012, :vhost=>"vhost_name", :username=>"user_name", :user=>"user_name", :password=>"my_secret_password", :pass=>"my_secret_password", :url=>"amqp://user_name:my_secret_password@10.12.0.10:15012/vhost_name" }
For further information on how to use RabbitMQ please refer to the bunny tutorial or the amqp gem tutorial.
Please sign in to leave a comment.
Comments
0 comments