amqp-boilerplate is a set of helper classes and modules to be used with the {github.com/ruby-amqp/amqp Ruby amqp gem}.
gem install amqp-boilerplate
See {AMQP::Boilerplate.configure} for configuration options.
Add a initializer amqp.rb
to your config/initializer folder with the following code:
Rails.configuration.threadsafe! AMQP::Boilerplate.configure do |config| config.logger = ::Rails.logger config.consumer_paths += %W( #{Rails.root}/app/consumers ) config.connection_options = { :host => "localhost", :port => 5672, :vhost => Rails.env } end # Require all files that are no longer auto-loaded when Rails is in thread-safe mode Dir[File.expand_path(File.join(Rails.root,'lib','**','*.rb'))].each {|f| require f} Dir[File.expand_path(File.join(Rails.root,'app','producers','**','*.rb'))].each {|f| require f} AMQP::Boilerplate.boot
amqp-boilerplate provides the AMQP::Boilerplate::Producer module for creating message producers, and the AMQP::Boilerplate::Consumer class for setting up a message consumer.
The following sample code shows a basic producer.
class MyProducer extend AMQP::Boilerplate::Producer amqp :routing_key => "hello.world" amqp_message :message def message "Look! I am a string that will be posted to the exchange." end end
For more information please refer to {AMQP::Boilerplate::Producer}
The following sample code shows a basic consumer.
class MyConsumer < AMQP::Boilerplate::Consumer amqp_queue "hello.world" def handle_message(payload, metadata) puts "Received message: #{payload}" end end
For more information please refer to {AMQP::Boilerplate::Consumer}
amqp-boilerplate is released under the MIT license.