No commit activity in last 3 years
No release in over 3 years
Collection of modules that aid in setting up AMQP producers and consumers.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.9
~> 2.6
~> 0.7

Runtime

~> 0.8
 Project Readme

amqp-boilerplate¶ ↑

amqp-boilerplate is a set of helper classes and modules to be used with the {github.com/ruby-amqp/amqp Ruby amqp gem}.

Install¶ ↑

gem install amqp-boilerplate

Configuration¶ ↑

See {AMQP::Boilerplate.configure} for configuration options.

Ruby on Rails¶ ↑

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 }
  config.on_unhandled_exception = Proc.new { |exception, consumer, metadata, payload|
    puts "Do something with exceptions: #{exception}"
  }
  config.consumer_prefetch = 10
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

Usage¶ ↑

amqp-boilerplate provides the AMQP::Boilerplate::Producer module for creating message producers, and the AMQP::Boilerplate::Consumer class for setting up a message consumer.

Producers¶ ↑

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}

Consumers¶ ↑

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}

License¶ ↑

amqp-boilerplate is released under the MIT license.