amqp-boilerplate 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -0
 - data/amqp-boilerplate.gemspec +1 -0
 - data/lib/amqp/boilerplate/consumer.rb +3 -0
 - data/lib/amqp/boilerplate/consumer_registry.rb +32 -0
 - data/lib/amqp/boilerplate/producer.rb +61 -4
 - data/lib/amqp/boilerplate/version.rb +1 -1
 - data/lib/amqp/boilerplate.rb +44 -0
 - data/spec/amqp/boilerplate/consumer_registry_spec.rb +72 -0
 - data/spec/amqp/boilerplate/consumer_spec.rb +13 -20
 - data/spec/amqp/boilerplate/logging_spec.rb +1 -1
 - data/spec/amqp/boilerplate/producer_spec.rb +5 -27
 - data/spec/amqp/boilerplate_spec.rb +81 -0
 - data/spec/fixtures/consumers/dummy_consumer.rb +3 -0
 - data/spec/spec_helper.rb +35 -0
 - metadata +26 -6
 
    
        data/.gitignore
    CHANGED
    
    
    
        data/amqp-boilerplate.gemspec
    CHANGED
    
    | 
         @@ -22,5 +22,6 @@ Gem::Specification.new do |s| 
     | 
|
| 
       22 
22 
     | 
    
         
             
              # specify any dependencies here; for example:
         
     | 
| 
       23 
23 
     | 
    
         
             
              s.add_development_dependency "rake", "~> 0.9"
         
     | 
| 
       24 
24 
     | 
    
         
             
              s.add_development_dependency "rspec", "~> 2.6"
         
     | 
| 
      
 25 
     | 
    
         
            +
              s.add_development_dependency "yard", "~> 0.7"
         
     | 
| 
       25 
26 
     | 
    
         
             
              s.add_runtime_dependency "amqp", "~> 0.8"
         
     | 
| 
       26 
27 
     | 
    
         
             
            end
         
     | 
| 
         @@ -5,6 +5,7 @@ module AMQP 
     | 
|
| 
       5 
5 
     | 
    
         
             
                    def amqp_queue(name=AMQ::Protocol::EMPTY_STRING, options={})
         
     | 
| 
       6 
6 
     | 
    
         
             
                      @queue_name = name
         
     | 
| 
       7 
7 
     | 
    
         
             
                      @queue_options = options
         
     | 
| 
      
 8 
     | 
    
         
            +
                      AMQP::Boilerplate.register_consumer(self)
         
     | 
| 
       8 
9 
     | 
    
         
             
                    end
         
     | 
| 
       9 
10 
     | 
    
         | 
| 
       10 
11 
     | 
    
         
             
                    def amqp_subscription(options={})
         
     | 
| 
         @@ -19,6 +20,8 @@ module AMQP 
     | 
|
| 
       19 
20 
     | 
    
         | 
| 
       20 
21 
     | 
    
         
             
                      queue = channel.queue(@queue_name, @queue_options)
         
     | 
| 
       21 
22 
     | 
    
         
             
                      queue.subscribe(@subscription_options, &consumer.method(:handle_message))
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                      AMQP::Boilerplate.logger.info("[#{self.name}.start] Started consumer '#{self.name}'")
         
     | 
| 
       22 
25 
     | 
    
         
             
                    end
         
     | 
| 
       23 
26 
     | 
    
         
             
                  end
         
     | 
| 
       24 
27 
     | 
    
         | 
| 
         @@ -0,0 +1,32 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module AMQP
         
     | 
| 
      
 2 
     | 
    
         
            +
              module Boilerplate
         
     | 
| 
      
 3 
     | 
    
         
            +
                module ConsumerRegistry
         
     | 
| 
      
 4 
     | 
    
         
            +
                  attr_writer :consumer_paths
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
                  def consumer_paths
         
     | 
| 
      
 7 
     | 
    
         
            +
                    @consumer_paths ||= []
         
     | 
| 
      
 8 
     | 
    
         
            +
                  end
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                  def load_consumers
         
     | 
| 
      
 11 
     | 
    
         
            +
                    consumer_paths.each do |dir|
         
     | 
| 
      
 12 
     | 
    
         
            +
                      Dir[File.join(dir, "*.rb")].each {|f| require f}
         
     | 
| 
      
 13 
     | 
    
         
            +
                    end
         
     | 
| 
      
 14 
     | 
    
         
            +
                  end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                  def registry
         
     | 
| 
      
 17 
     | 
    
         
            +
                    @registry ||= []
         
     | 
| 
      
 18 
     | 
    
         
            +
                  end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                  def register_consumer(klass)
         
     | 
| 
      
 21 
     | 
    
         
            +
                    AMQP::Boilerplate.logger.info("[#{self.name}#register_consumer] Registered consumer '#{klass.name}'")
         
     | 
| 
      
 22 
     | 
    
         
            +
                    registry << klass
         
     | 
| 
      
 23 
     | 
    
         
            +
                  end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                  def start_consumers
         
     | 
| 
      
 26 
     | 
    
         
            +
                    registry.each do |consumer|
         
     | 
| 
      
 27 
     | 
    
         
            +
                      consumer.start
         
     | 
| 
      
 28 
     | 
    
         
            +
                    end
         
     | 
| 
      
 29 
     | 
    
         
            +
                  end
         
     | 
| 
      
 30 
     | 
    
         
            +
                end
         
     | 
| 
      
 31 
     | 
    
         
            +
              end
         
     | 
| 
      
 32 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -1,32 +1,84 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module AMQP
         
     | 
| 
       2 
2 
     | 
    
         
             
              module Boilerplate
         
     | 
| 
      
 3 
     | 
    
         
            +
                # Use this module to turn a class into a potential producer that can
         
     | 
| 
      
 4 
     | 
    
         
            +
                # deliver messages to an AMQP exchange.
         
     | 
| 
      
 5 
     | 
    
         
            +
                #
         
     | 
| 
      
 6 
     | 
    
         
            +
                # @example Getting started
         
     | 
| 
      
 7 
     | 
    
         
            +
                #   class MyProducer
         
     | 
| 
      
 8 
     | 
    
         
            +
                #     extend AMQP::Boilerplate::Producer
         
     | 
| 
      
 9 
     | 
    
         
            +
                #
         
     | 
| 
      
 10 
     | 
    
         
            +
                #     amqp :routing_key => "hello.world"
         
     | 
| 
      
 11 
     | 
    
         
            +
                #     amqp_message :message
         
     | 
| 
      
 12 
     | 
    
         
            +
                #
         
     | 
| 
      
 13 
     | 
    
         
            +
                #     def message
         
     | 
| 
      
 14 
     | 
    
         
            +
                #       "Look! I am a string that will be posted to the exchange."
         
     | 
| 
      
 15 
     | 
    
         
            +
                #     end
         
     | 
| 
      
 16 
     | 
    
         
            +
                #   end
         
     | 
| 
      
 17 
     | 
    
         
            +
                #
         
     | 
| 
      
 18 
     | 
    
         
            +
                # @example Configuring exchange
         
     | 
| 
      
 19 
     | 
    
         
            +
                #   class MyProducer
         
     | 
| 
      
 20 
     | 
    
         
            +
                #     extend AMQP::Boilerplate::Producer
         
     | 
| 
      
 21 
     | 
    
         
            +
                #
         
     | 
| 
      
 22 
     | 
    
         
            +
                #     amqp :routing_key => "hello.world"
         
     | 
| 
      
 23 
     | 
    
         
            +
                #     amqp_exchange :fanout, "amq.fanout", :durable => true
         
     | 
| 
      
 24 
     | 
    
         
            +
                #     amqp_message :message
         
     | 
| 
      
 25 
     | 
    
         
            +
                #
         
     | 
| 
      
 26 
     | 
    
         
            +
                #     def message
         
     | 
| 
      
 27 
     | 
    
         
            +
                #       "Look! I am a string that will be posted to the exchange."
         
     | 
| 
      
 28 
     | 
    
         
            +
                #     end
         
     | 
| 
      
 29 
     | 
    
         
            +
                #   end
         
     | 
| 
       3 
30 
     | 
    
         
             
                module Producer
         
     | 
| 
       4 
     | 
    
         
            -
                   
     | 
| 
      
 31 
     | 
    
         
            +
                  # Macro that sets up amqp for a class.
         
     | 
| 
      
 32 
     | 
    
         
            +
                  #
         
     | 
| 
      
 33 
     | 
    
         
            +
                  # @param [Hash] opts Options that will be passed to +AMQP::Exchange#publish
         
     | 
| 
      
 34 
     | 
    
         
            +
                  # @return [void]
         
     | 
| 
      
 35 
     | 
    
         
            +
                  def amqp(opts={})
         
     | 
| 
       5 
36 
     | 
    
         
             
                    send :include, InstanceMethods
         
     | 
| 
       6 
     | 
    
         
            -
                    @amqp_boilerplate_options =  
     | 
| 
      
 37 
     | 
    
         
            +
                    @amqp_boilerplate_options = opts
         
     | 
| 
       7 
38 
     | 
    
         
             
                  end
         
     | 
| 
       8 
39 
     | 
    
         | 
| 
       9 
     | 
    
         
            -
                   
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
      
 40 
     | 
    
         
            +
                  # Configuration for the exchange to be used
         
     | 
| 
      
 41 
     | 
    
         
            +
                  #
         
     | 
| 
      
 42 
     | 
    
         
            +
                  # @param [Symbol] type Exchange type
         
     | 
| 
      
 43 
     | 
    
         
            +
                  # @param [String] name Exchange name
         
     | 
| 
      
 44 
     | 
    
         
            +
                  # @param [Hash] opts a customizable set of options
         
     | 
| 
      
 45 
     | 
    
         
            +
                  # @see AMQP::Exchange#initialize
         
     | 
| 
      
 46 
     | 
    
         
            +
                  # @return [void]
         
     | 
| 
      
 47 
     | 
    
         
            +
                  def amqp_exchange(type=:direct, name=AMQ::Protocol::EMPTY_STRING, opts={})
         
     | 
| 
      
 48 
     | 
    
         
            +
                    @amqp_boilerplate_exchange = [type, name, opts]
         
     | 
| 
       11 
49 
     | 
    
         
             
                  end
         
     | 
| 
       12 
50 
     | 
    
         | 
| 
      
 51 
     | 
    
         
            +
                  # Choose the method that will return the actual message (payload) to be
         
     | 
| 
      
 52 
     | 
    
         
            +
                  # delivered to the exchange
         
     | 
| 
      
 53 
     | 
    
         
            +
                  #
         
     | 
| 
      
 54 
     | 
    
         
            +
                  # This method SHOULD return a string.
         
     | 
| 
      
 55 
     | 
    
         
            +
                  #
         
     | 
| 
      
 56 
     | 
    
         
            +
                  # @param [Symbol] method_name Name of method that generates message
         
     | 
| 
      
 57 
     | 
    
         
            +
                  # @return [void]
         
     | 
| 
       13 
58 
     | 
    
         
             
                  def amqp_message(method_name)
         
     | 
| 
       14 
59 
     | 
    
         
             
                    @amqp_boilerplate_message = method_name
         
     | 
| 
       15 
60 
     | 
    
         
             
                  end
         
     | 
| 
       16 
61 
     | 
    
         | 
| 
      
 62 
     | 
    
         
            +
                  # TODO Can we do this in a nicer way?
         
     | 
| 
       17 
63 
     | 
    
         
             
                  def amqp_boilerplate_options
         
     | 
| 
       18 
64 
     | 
    
         
             
                    @amqp_boilerplate_options
         
     | 
| 
       19 
65 
     | 
    
         
             
                  end
         
     | 
| 
       20 
66 
     | 
    
         | 
| 
      
 67 
     | 
    
         
            +
                  # TODO Can we do this in a nicer way?
         
     | 
| 
       21 
68 
     | 
    
         
             
                  def amqp_boilerplate_exchange
         
     | 
| 
       22 
69 
     | 
    
         
             
                    @amqp_boilerplate_exchange || amqp_exchange
         
     | 
| 
       23 
70 
     | 
    
         
             
                  end
         
     | 
| 
       24 
71 
     | 
    
         | 
| 
      
 72 
     | 
    
         
            +
                  # TODO Can we do this in a nicer way?
         
     | 
| 
       25 
73 
     | 
    
         
             
                  def amqp_boilerplate_message
         
     | 
| 
       26 
74 
     | 
    
         
             
                    @amqp_boilerplate_message
         
     | 
| 
       27 
75 
     | 
    
         
             
                  end
         
     | 
| 
       28 
76 
     | 
    
         | 
| 
       29 
77 
     | 
    
         
             
                  module InstanceMethods
         
     | 
| 
      
 78 
     | 
    
         
            +
                    # Publishes a message to the exchange
         
     | 
| 
      
 79 
     | 
    
         
            +
                    #
         
     | 
| 
      
 80 
     | 
    
         
            +
                    # @see AMQP::Exchange#publish
         
     | 
| 
      
 81 
     | 
    
         
            +
                    # @return [void]
         
     | 
| 
       30 
82 
     | 
    
         
             
                    def publish
         
     | 
| 
       31 
83 
     | 
    
         
             
                      message = send(self.class.amqp_boilerplate_message.to_sym)
         
     | 
| 
       32 
84 
     | 
    
         
             
                      exchange.publish(message, self.class.amqp_boilerplate_options) do
         
     | 
| 
         @@ -36,6 +88,11 @@ module AMQP 
     | 
|
| 
       36 
88 
     | 
    
         | 
| 
       37 
89 
     | 
    
         
             
                  private
         
     | 
| 
       38 
90 
     | 
    
         | 
| 
      
 91 
     | 
    
         
            +
                    # Instantiates a new exchange, additional configuration can be given
         
     | 
| 
      
 92 
     | 
    
         
            +
                    # through the +amqp_exchange+ class macro.
         
     | 
| 
      
 93 
     | 
    
         
            +
                    #
         
     | 
| 
      
 94 
     | 
    
         
            +
                    # @see AMQP::Exchange#initialize
         
     | 
| 
      
 95 
     | 
    
         
            +
                    # @return [AMQP::Exchange]
         
     | 
| 
       39 
96 
     | 
    
         
             
                    def exchange
         
     | 
| 
       40 
97 
     | 
    
         
             
                      AMQP::Exchange.new(AMQP.channel, *self.class.amqp_boilerplate_exchange)
         
     | 
| 
       41 
98 
     | 
    
         
             
                    end
         
     | 
    
        data/lib/amqp/boilerplate.rb
    CHANGED
    
    | 
         @@ -1,17 +1,61 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'amqp'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'amqp/utilities/event_loop_helper'
         
     | 
| 
       2 
3 
     | 
    
         | 
| 
       3 
4 
     | 
    
         
             
            require 'amqp/boilerplate/version'
         
     | 
| 
       4 
5 
     | 
    
         | 
| 
       5 
6 
     | 
    
         
             
            require 'amqp/boilerplate/consumer'
         
     | 
| 
      
 7 
     | 
    
         
            +
            require 'amqp/boilerplate/consumer_registry'
         
     | 
| 
       6 
8 
     | 
    
         
             
            require 'amqp/boilerplate/logging'
         
     | 
| 
       7 
9 
     | 
    
         
             
            require 'amqp/boilerplate/producer'
         
     | 
| 
       8 
10 
     | 
    
         | 
| 
       9 
11 
     | 
    
         
             
            module AMQP
         
     | 
| 
       10 
12 
     | 
    
         
             
              module Boilerplate
         
     | 
| 
      
 13 
     | 
    
         
            +
                extend ConsumerRegistry
         
     | 
| 
       11 
14 
     | 
    
         
             
                extend Logging
         
     | 
| 
       12 
15 
     | 
    
         | 
| 
      
 16 
     | 
    
         
            +
                def self.boot
         
     | 
| 
      
 17 
     | 
    
         
            +
                  if defined?(PhusionPassenger)
         
     | 
| 
      
 18 
     | 
    
         
            +
                    PhusionPassenger.on_event(:starting_worker_process) do |forked|
         
     | 
| 
      
 19 
     | 
    
         
            +
                      if forked
         
     | 
| 
      
 20 
     | 
    
         
            +
                        amqp_thread = Thread.new {
         
     | 
| 
      
 21 
     | 
    
         
            +
                          AMQP::Boilerplate.start
         
     | 
| 
      
 22 
     | 
    
         
            +
                        }
         
     | 
| 
      
 23 
     | 
    
         
            +
                        amqp_thread.abort_on_exception = true
         
     | 
| 
      
 24 
     | 
    
         
            +
                      end
         
     | 
| 
      
 25 
     | 
    
         
            +
                    end
         
     | 
| 
      
 26 
     | 
    
         
            +
                  else
         
     | 
| 
      
 27 
     | 
    
         
            +
                    AMQP::Utilities::EventLoopHelper.run do
         
     | 
| 
      
 28 
     | 
    
         
            +
                      AMQP::Boilerplate.start
         
     | 
| 
      
 29 
     | 
    
         
            +
                    end
         
     | 
| 
      
 30 
     | 
    
         
            +
                  end
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                  sleep(0.25)
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                  AMQP::Boilerplate.logger.info("[#{self.name}.boot] Started AMQP (Server Type: #{AMQP::Utilities::EventLoopHelper.server_type})")
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                  EventMachine.next_tick do
         
     | 
| 
      
 37 
     | 
    
         
            +
                    AMQP.channel ||= AMQP::Channel.new(AMQP.connection)
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                    load_consumers
         
     | 
| 
      
 40 
     | 
    
         
            +
                    start_consumers
         
     | 
| 
      
 41 
     | 
    
         
            +
                  end
         
     | 
| 
      
 42 
     | 
    
         
            +
                end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                # TODO Documentation!
         
     | 
| 
       13 
45 
     | 
    
         
             
                def self.configure
         
     | 
| 
       14 
46 
     | 
    
         
             
                  yield self if block_given?
         
     | 
| 
       15 
47 
     | 
    
         
             
                end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                def self.connection_options
         
     | 
| 
      
 50 
     | 
    
         
            +
                  @connection_options
         
     | 
| 
      
 51 
     | 
    
         
            +
                end
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
                def self.connection_options=(options)
         
     | 
| 
      
 54 
     | 
    
         
            +
                  @connection_options = options
         
     | 
| 
      
 55 
     | 
    
         
            +
                end
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
                def self.start
         
     | 
| 
      
 58 
     | 
    
         
            +
                  AMQP.start self.connection_options
         
     | 
| 
      
 59 
     | 
    
         
            +
                end
         
     | 
| 
       16 
60 
     | 
    
         
             
              end
         
     | 
| 
       17 
61 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,72 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            describe AMQP::Boilerplate::ConsumerRegistry do
         
     | 
| 
      
 4 
     | 
    
         
            +
              before(:each) do
         
     | 
| 
      
 5 
     | 
    
         
            +
                AMQP::Boilerplate.stub(:logger).and_return(mock.as_null_object)
         
     | 
| 
      
 6 
     | 
    
         
            +
              end
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
              describe "#consumer_paths" do
         
     | 
| 
      
 9 
     | 
    
         
            +
                it "should be an Array" do
         
     | 
| 
      
 10 
     | 
    
         
            +
                  AMQP::Boilerplate.consumer_paths.should be_an(Array)
         
     | 
| 
      
 11 
     | 
    
         
            +
                end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                it "should always return the same Array" do
         
     | 
| 
      
 14 
     | 
    
         
            +
                  consumer_paths = AMQP::Boilerplate.consumer_paths
         
     | 
| 
      
 15 
     | 
    
         
            +
                  AMQP::Boilerplate.consumer_paths.should equal(consumer_paths)
         
     | 
| 
      
 16 
     | 
    
         
            +
                end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                it "should default to an empty Array" do
         
     | 
| 
      
 19 
     | 
    
         
            +
                  AMQP::Boilerplate.consumer_paths.should be_empty
         
     | 
| 
      
 20 
     | 
    
         
            +
                end
         
     | 
| 
      
 21 
     | 
    
         
            +
              end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
              describe "#load_consumers" do
         
     | 
| 
      
 24 
     | 
    
         
            +
                before(:each) do
         
     | 
| 
      
 25 
     | 
    
         
            +
                  AMQP::Boilerplate.stub(:registry).and_return([])
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                it "should require all files in configured consumer_paths" do
         
     | 
| 
      
 29 
     | 
    
         
            +
                  AMQP::Boilerplate.consumer_paths << File.expand_path(File.join(File.dirname(__FILE__), '..', '..', "fixtures/consumers"))
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                  defined?(DummyConsumer).should be_nil
         
     | 
| 
      
 32 
     | 
    
         
            +
                  AMQP::Boilerplate.load_consumers
         
     | 
| 
      
 33 
     | 
    
         
            +
                  defined?(DummyConsumer).should_not be_nil
         
     | 
| 
      
 34 
     | 
    
         
            +
                end
         
     | 
| 
      
 35 
     | 
    
         
            +
              end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
              describe "#register_consumer" do
         
     | 
| 
      
 38 
     | 
    
         
            +
                before(:each) do
         
     | 
| 
      
 39 
     | 
    
         
            +
                  AMQP::Boilerplate.stub(:registry).and_return(Array.new)
         
     | 
| 
      
 40 
     | 
    
         
            +
                end
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                it "should call #registry" do
         
     | 
| 
      
 43 
     | 
    
         
            +
                  AMQP::Boilerplate.should_receive(:registry).once
         
     | 
| 
      
 44 
     | 
    
         
            +
                  AMQP::Boilerplate.register_consumer(mock.as_null_object)
         
     | 
| 
      
 45 
     | 
    
         
            +
                end
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                it "should add classes to registry" do
         
     | 
| 
      
 48 
     | 
    
         
            +
                  expect {
         
     | 
| 
      
 49 
     | 
    
         
            +
                    AMQP::Boilerplate.register_consumer(mock.as_null_object)
         
     | 
| 
      
 50 
     | 
    
         
            +
                  }.to change(AMQP::Boilerplate.registry, :size).by(1)
         
     | 
| 
      
 51 
     | 
    
         
            +
                end
         
     | 
| 
      
 52 
     | 
    
         
            +
              end
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
              describe "#registry" do
         
     | 
| 
      
 55 
     | 
    
         
            +
                it "should return an Array" do
         
     | 
| 
      
 56 
     | 
    
         
            +
                  AMQP::Boilerplate.registry.should be_an(Array)
         
     | 
| 
      
 57 
     | 
    
         
            +
                end
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
                it "should always return the same array" do
         
     | 
| 
      
 60 
     | 
    
         
            +
                  registry = AMQP::Boilerplate.registry
         
     | 
| 
      
 61 
     | 
    
         
            +
                  AMQP::Boilerplate.registry.should equal(registry)
         
     | 
| 
      
 62 
     | 
    
         
            +
                end
         
     | 
| 
      
 63 
     | 
    
         
            +
              end
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
              describe "#start_consumers" do
         
     | 
| 
      
 66 
     | 
    
         
            +
                it "should call .start on all registered consumer classes" do
         
     | 
| 
      
 67 
     | 
    
         
            +
                  FooConsumer.should_receive(:start)
         
     | 
| 
      
 68 
     | 
    
         
            +
                  BarConsumer.should_receive(:start)
         
     | 
| 
      
 69 
     | 
    
         
            +
                  AMQP::Boilerplate.start_consumers
         
     | 
| 
      
 70 
     | 
    
         
            +
                end
         
     | 
| 
      
 71 
     | 
    
         
            +
              end
         
     | 
| 
      
 72 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -1,16 +1,9 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
              amqp_queue "queue.name.here", :durable => true
         
     | 
| 
       5 
     | 
    
         
            -
              amqp_subscription :ack => true
         
     | 
| 
       6 
     | 
    
         
            -
            end
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
            class FooConsumer < AMQP::Boilerplate::Consumer
         
     | 
| 
       9 
     | 
    
         
            -
              amqp_queue
         
     | 
| 
       10 
     | 
    
         
            -
            end
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
      
 3 
     | 
    
         
            +
            # NOTE See spec_helper for Consumer definitions
         
     | 
| 
       12 
4 
     | 
    
         
             
            describe AMQP::Boilerplate::Consumer do
         
     | 
| 
       13 
5 
     | 
    
         
             
              before(:each) do
         
     | 
| 
      
 6 
     | 
    
         
            +
                AMQP::Boilerplate.stub(:logger).and_return(mock.as_null_object)
         
     | 
| 
       14 
7 
     | 
    
         
             
                @channel = mock(AMQP::Channel)
         
     | 
| 
       15 
8 
     | 
    
         
             
                @channel.stub(:on_error).and_return(true)
         
     | 
| 
       16 
9 
     | 
    
         
             
              end
         
     | 
| 
         @@ -21,9 +14,9 @@ describe AMQP::Boilerplate::Consumer do 
     | 
|
| 
       21 
14 
     | 
    
         
             
                end
         
     | 
| 
       22 
15 
     | 
    
         | 
| 
       23 
16 
     | 
    
         
             
                it "should log the code and message" do
         
     | 
| 
       24 
     | 
    
         
            -
                  AMQP::Boilerplate.logger.should_receive(:error).with("[ 
     | 
| 
      
 17 
     | 
    
         
            +
                  AMQP::Boilerplate.logger.should_receive(:error).with("[BarConsumer#handle_channel_error] Code = #{@channel_close.reply_code}, message = #{@channel_close.reply_text}")
         
     | 
| 
       25 
18 
     | 
    
         | 
| 
       26 
     | 
    
         
            -
                   
     | 
| 
      
 19 
     | 
    
         
            +
                  BarConsumer.new.handle_channel_error(@channel, @channel_close)
         
     | 
| 
       27 
20 
     | 
    
         
             
                end
         
     | 
| 
       28 
21 
     | 
    
         
             
              end
         
     | 
| 
       29 
22 
     | 
    
         | 
| 
         @@ -58,8 +51,8 @@ describe AMQP::Boilerplate::Consumer do 
     | 
|
| 
       58 
51 
     | 
    
         | 
| 
       59 
52 
     | 
    
         
             
              describe ".start" do
         
     | 
| 
       60 
53 
     | 
    
         
             
                before(:each) do
         
     | 
| 
       61 
     | 
    
         
            -
                  @consumer =  
     | 
| 
       62 
     | 
    
         
            -
                   
     | 
| 
      
 54 
     | 
    
         
            +
                  @consumer = BarConsumer.new
         
     | 
| 
      
 55 
     | 
    
         
            +
                  BarConsumer.stub(:new).and_return(@consumer)
         
     | 
| 
       63 
56 
     | 
    
         | 
| 
       64 
57 
     | 
    
         
             
                  AMQP.stub(:channel).and_return(@channel)
         
     | 
| 
       65 
58 
     | 
    
         | 
| 
         @@ -70,32 +63,32 @@ describe AMQP::Boilerplate::Consumer do 
     | 
|
| 
       70 
63 
     | 
    
         | 
| 
       71 
64 
     | 
    
         
             
                it "should use a channel" do
         
     | 
| 
       72 
65 
     | 
    
         
             
                  AMQP.should_receive(:channel).and_return(@channel)
         
     | 
| 
       73 
     | 
    
         
            -
                   
     | 
| 
      
 66 
     | 
    
         
            +
                  BarConsumer.start
         
     | 
| 
       74 
67 
     | 
    
         
             
                end
         
     | 
| 
       75 
68 
     | 
    
         | 
| 
       76 
69 
     | 
    
         
             
                it "should instantiate a consumer" do
         
     | 
| 
       77 
     | 
    
         
            -
                   
     | 
| 
       78 
     | 
    
         
            -
                   
     | 
| 
      
 70 
     | 
    
         
            +
                  BarConsumer.should_receive(:new).and_return(@consumer)
         
     | 
| 
      
 71 
     | 
    
         
            +
                  BarConsumer.start
         
     | 
| 
       79 
72 
     | 
    
         
             
                end
         
     | 
| 
       80 
73 
     | 
    
         | 
| 
       81 
74 
     | 
    
         
             
                it "should register a channel error handler" do
         
     | 
| 
       82 
75 
     | 
    
         
             
                  @channel.should_receive(:on_error)
         
     | 
| 
       83 
     | 
    
         
            -
                   
     | 
| 
      
 76 
     | 
    
         
            +
                  BarConsumer.start
         
     | 
| 
       84 
77 
     | 
    
         
             
                end
         
     | 
| 
       85 
78 
     | 
    
         | 
| 
       86 
79 
     | 
    
         
             
                it "should instantiate a queue with the proper queue name" do
         
     | 
| 
       87 
80 
     | 
    
         
             
                  @channel.should_receive(:queue).with("queue.name.here", anything)
         
     | 
| 
       88 
     | 
    
         
            -
                   
     | 
| 
      
 81 
     | 
    
         
            +
                  BarConsumer.start
         
     | 
| 
       89 
82 
     | 
    
         
             
                end
         
     | 
| 
       90 
83 
     | 
    
         | 
| 
       91 
84 
     | 
    
         
             
                it "should instantiate a queue provided with options" do
         
     | 
| 
       92 
85 
     | 
    
         
             
                  @channel.should_receive(:queue).with(anything, :durable => true)
         
     | 
| 
       93 
     | 
    
         
            -
                   
     | 
| 
      
 86 
     | 
    
         
            +
                  BarConsumer.start
         
     | 
| 
       94 
87 
     | 
    
         
             
                end
         
     | 
| 
       95 
88 
     | 
    
         | 
| 
       96 
89 
     | 
    
         
             
                it "should subscribe to the queue" do
         
     | 
| 
       97 
90 
     | 
    
         
             
                  @queue.should_receive(:subscribe).with(:ack => true)
         
     | 
| 
       98 
     | 
    
         
            -
                   
     | 
| 
      
 91 
     | 
    
         
            +
                  BarConsumer.start
         
     | 
| 
       99 
92 
     | 
    
         
             
                end
         
     | 
| 
       100 
93 
     | 
    
         
             
              end
         
     | 
| 
       101 
94 
     | 
    
         
             
            end
         
     | 
| 
         @@ -9,7 +9,7 @@ describe AMQP::Boilerplate::Logging do 
     | 
|
| 
       9 
9 
     | 
    
         
             
              describe "#logger" do
         
     | 
| 
       10 
10 
     | 
    
         
             
                it "should set the logger to use" do
         
     | 
| 
       11 
11 
     | 
    
         
             
                  MyLogger = Class.new
         
     | 
| 
       12 
     | 
    
         
            -
                  AMQP::Boilerplate.logger = MyLogger 
     | 
| 
      
 12 
     | 
    
         
            +
                  AMQP::Boilerplate.logger = MyLogger
         
     | 
| 
       13 
13 
     | 
    
         
             
                  AMQP::Boilerplate.logger.should == MyLogger
         
     | 
| 
       14 
14 
     | 
    
         
             
                end
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
         @@ -1,28 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
              extend AMQP::Boilerplate::Producer
         
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
              amqp :routing_key => "some.routing.key"
         
     | 
| 
       7 
     | 
    
         
            -
              amqp_exchange :fanout, "amq.fanout", { :durable => true }
         
     | 
| 
       8 
     | 
    
         
            -
              amqp_message :message
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
              def message
         
     | 
| 
       11 
     | 
    
         
            -
                "hello world!"
         
     | 
| 
       12 
     | 
    
         
            -
              end
         
     | 
| 
       13 
     | 
    
         
            -
            end
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
            class FooProducer
         
     | 
| 
       16 
     | 
    
         
            -
              extend AMQP::Boilerplate::Producer
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
              amqp :routing_key => "another.routing.key"
         
     | 
| 
       19 
     | 
    
         
            -
              amqp_message :some_method
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
              def some_method
         
     | 
| 
       22 
     | 
    
         
            -
                'Foo Bar'
         
     | 
| 
       23 
     | 
    
         
            -
              end
         
     | 
| 
       24 
     | 
    
         
            -
            end
         
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
      
 3 
     | 
    
         
            +
            # NOTE See spec_helper for Producer definitions
         
     | 
| 
       26 
4 
     | 
    
         
             
            describe AMQP::Boilerplate::Producer do
         
     | 
| 
       27 
5 
     | 
    
         
             
              before(:each) do
         
     | 
| 
       28 
6 
     | 
    
         
             
                AMQP::Boilerplate.stub(:logger).and_return(mock.as_null_object)
         
     | 
| 
         @@ -31,7 +9,7 @@ describe AMQP::Boilerplate::Producer do 
     | 
|
| 
       31 
9 
     | 
    
         
             
                @exchange.stub(:publish).and_yield
         
     | 
| 
       32 
10 
     | 
    
         
             
                AMQP::Exchange.stub!(:new).and_return(@exchange)
         
     | 
| 
       33 
11 
     | 
    
         | 
| 
       34 
     | 
    
         
            -
                @producer =  
     | 
| 
      
 12 
     | 
    
         
            +
                @producer = BarProducer.new
         
     | 
| 
       35 
13 
     | 
    
         
             
              end
         
     | 
| 
       36 
14 
     | 
    
         | 
| 
       37 
15 
     | 
    
         
             
              describe ".amqp_exchange" do
         
     | 
| 
         @@ -63,11 +41,11 @@ describe AMQP::Boilerplate::Producer do 
     | 
|
| 
       63 
41 
     | 
    
         
             
                end
         
     | 
| 
       64 
42 
     | 
    
         | 
| 
       65 
43 
     | 
    
         
             
                it "should pass options to AMQP::Exchange#publish" do
         
     | 
| 
       66 
     | 
    
         
            -
                   
     | 
| 
      
 44 
     | 
    
         
            +
                  BarProducer.amqp({ :routing_key => "some.routing.key", :mandatory => true })
         
     | 
| 
       67 
45 
     | 
    
         
             
                  @exchange.should_receive(:publish).with(@producer.message, :routing_key => "some.routing.key", :mandatory => true)
         
     | 
| 
       68 
46 
     | 
    
         
             
                  @producer.publish
         
     | 
| 
       69 
47 
     | 
    
         | 
| 
       70 
     | 
    
         
            -
                   
     | 
| 
      
 48 
     | 
    
         
            +
                  BarProducer.amqp({ :routing_key => "some.routing.key", :mandatory => true, :immediate => true })
         
     | 
| 
       71 
49 
     | 
    
         
             
                  @exchange.should_receive(:publish).with(@producer.message, :routing_key => "some.routing.key", :mandatory => true, :immediate => true)
         
     | 
| 
       72 
50 
     | 
    
         
             
                  @producer.publish
         
     | 
| 
       73 
51 
     | 
    
         
             
                end
         
     | 
| 
         @@ -89,7 +67,7 @@ describe AMQP::Boilerplate::Producer do 
     | 
|
| 
       89 
67 
     | 
    
         
             
                  end
         
     | 
| 
       90 
68 
     | 
    
         | 
| 
       91 
69 
     | 
    
         
             
                  it "should use defaults for exchange configuration" do
         
     | 
| 
       92 
     | 
    
         
            -
                     
     | 
| 
      
 70 
     | 
    
         
            +
                    BarProducer.amqp_exchange()
         
     | 
| 
       93 
71 
     | 
    
         | 
| 
       94 
72 
     | 
    
         
             
                    AMQP::Exchange.should_receive(:new).with(@channel, :direct, AMQ::Protocol::EMPTY_STRING, {})
         
     | 
| 
       95 
73 
     | 
    
         
             
                    @producer.publish
         
     | 
| 
         @@ -1,6 +1,62 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            describe AMQP::Boilerplate do
         
     | 
| 
      
 4 
     | 
    
         
            +
              describe ".boot" do
         
     | 
| 
      
 5 
     | 
    
         
            +
                before(:each) do
         
     | 
| 
      
 6 
     | 
    
         
            +
                  AMQP::Boilerplate.stub(:logger).and_return(mock.as_null_object)
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
                  EventMachine.stub(:next_tick).and_yield
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                  AMQP::Boilerplate.stub(:start_consumers)
         
     | 
| 
      
 11 
     | 
    
         
            +
                  AMQP::Boilerplate.stub(:load_consumers)
         
     | 
| 
      
 12 
     | 
    
         
            +
                end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                it "should load all consumers" do
         
     | 
| 
      
 15 
     | 
    
         
            +
                  AMQP::Boilerplate.should_receive(:load_consumers)
         
     | 
| 
      
 16 
     | 
    
         
            +
                  AMQP::Boilerplate.boot
         
     | 
| 
      
 17 
     | 
    
         
            +
                end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                it "should start all consumers" do
         
     | 
| 
      
 20 
     | 
    
         
            +
                  AMQP::Boilerplate.should_receive(:start_consumers)
         
     | 
| 
      
 21 
     | 
    
         
            +
                  AMQP::Boilerplate.boot
         
     | 
| 
      
 22 
     | 
    
         
            +
                end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                it "should connect to AMQP" do
         
     | 
| 
      
 25 
     | 
    
         
            +
                  AMQP::Boilerplate.should_receive(:start)
         
     | 
| 
      
 26 
     | 
    
         
            +
                  AMQP::Boilerplate.boot
         
     | 
| 
      
 27 
     | 
    
         
            +
                end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                describe "when using passenger" do
         
     | 
| 
      
 30 
     | 
    
         
            +
                  before(:each) do
         
     | 
| 
      
 31 
     | 
    
         
            +
                    PhusionPassenger = Class.new
         
     | 
| 
      
 32 
     | 
    
         
            +
                    PhusionPassenger.stub(:on_event).and_yield(true)
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                    @thread = mock(Thread, :abort_on_exception= => nil)
         
     | 
| 
      
 35 
     | 
    
         
            +
                    Thread.stub(:new).and_yield.and_return(@thread)
         
     | 
| 
      
 36 
     | 
    
         
            +
                  end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                  # Don't try this at home!
         
     | 
| 
      
 39 
     | 
    
         
            +
                  after(:each) do
         
     | 
| 
      
 40 
     | 
    
         
            +
                    Object.send(:remove_const, "PhusionPassenger")
         
     | 
| 
      
 41 
     | 
    
         
            +
                  end
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                  it "should register to starting_worker_process event" do
         
     | 
| 
      
 44 
     | 
    
         
            +
                    PhusionPassenger.should_receive(:on_event).with(:starting_worker_process)
         
     | 
| 
      
 45 
     | 
    
         
            +
                    AMQP::Boilerplate.boot
         
     | 
| 
      
 46 
     | 
    
         
            +
                  end
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
                  it "should start new thread after process forked" do
         
     | 
| 
      
 49 
     | 
    
         
            +
                    Thread.should_receive(:new)
         
     | 
| 
      
 50 
     | 
    
         
            +
                    AMQP::Boilerplate.boot
         
     | 
| 
      
 51 
     | 
    
         
            +
                  end
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
                  it "should abort thread on exception" do
         
     | 
| 
      
 54 
     | 
    
         
            +
                    @thread.should_receive(:abort_on_exception=).with(true)
         
     | 
| 
      
 55 
     | 
    
         
            +
                    AMQP::Boilerplate.boot
         
     | 
| 
      
 56 
     | 
    
         
            +
                  end
         
     | 
| 
      
 57 
     | 
    
         
            +
                end
         
     | 
| 
      
 58 
     | 
    
         
            +
              end
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
       4 
60 
     | 
    
         
             
              describe ".configure" do
         
     | 
| 
       5 
61 
     | 
    
         
             
                after(:each) do
         
     | 
| 
       6 
62 
     | 
    
         
             
                  AMQP::Boilerplate.logger = nil
         
     | 
| 
         @@ -11,5 +67,30 @@ describe AMQP::Boilerplate do 
     | 
|
| 
       11 
67 
     | 
    
         
             
                  AMQP::Boilerplate.configure { |config| config.logger = MyFunkyLogger }
         
     | 
| 
       12 
68 
     | 
    
         
             
                  AMQP::Boilerplate.logger.should == MyFunkyLogger
         
     | 
| 
       13 
69 
     | 
    
         
             
                end
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
                it "should let us choose where consumers can be found" do
         
     | 
| 
      
 72 
     | 
    
         
            +
                  consumer_path = 'app/consumers'
         
     | 
| 
      
 73 
     | 
    
         
            +
                  AMQP::Boilerplate.configure { |config| config.consumer_paths << consumer_path }
         
     | 
| 
      
 74 
     | 
    
         
            +
                  AMQP::Boilerplate.consumer_paths.should include(consumer_path)
         
     | 
| 
      
 75 
     | 
    
         
            +
                end
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
                it "should allow us to set connection options" do
         
     | 
| 
      
 78 
     | 
    
         
            +
                  connection_options = { :host => "localhost", :port => 5672 }
         
     | 
| 
      
 79 
     | 
    
         
            +
                  AMQP::Boilerplate.configure { |config| config.connection_options = connection_options }
         
     | 
| 
      
 80 
     | 
    
         
            +
                  AMQP::Boilerplate.connection_options.should == connection_options
         
     | 
| 
      
 81 
     | 
    
         
            +
                end
         
     | 
| 
      
 82 
     | 
    
         
            +
              end
         
     | 
| 
      
 83 
     | 
    
         
            +
             
     | 
| 
      
 84 
     | 
    
         
            +
              describe ".start" do
         
     | 
| 
      
 85 
     | 
    
         
            +
                it "should start AMQP" do
         
     | 
| 
      
 86 
     | 
    
         
            +
                  AMQP.should_receive(:start)
         
     | 
| 
      
 87 
     | 
    
         
            +
                  AMQP::Boilerplate.start
         
     | 
| 
      
 88 
     | 
    
         
            +
                end
         
     | 
| 
      
 89 
     | 
    
         
            +
             
     | 
| 
      
 90 
     | 
    
         
            +
                it "should use the connection options" do
         
     | 
| 
      
 91 
     | 
    
         
            +
                  AMQP::Boilerplate.connection_options = { :host => "localhost", :port => 5672 }
         
     | 
| 
      
 92 
     | 
    
         
            +
                  AMQP.should_receive(:start).with(AMQP::Boilerplate.connection_options)
         
     | 
| 
      
 93 
     | 
    
         
            +
                  AMQP::Boilerplate.start
         
     | 
| 
      
 94 
     | 
    
         
            +
                end
         
     | 
| 
       14 
95 
     | 
    
         
             
              end
         
     | 
| 
       15 
96 
     | 
    
         
             
            end
         
     | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    | 
         @@ -5,3 +5,38 @@ require 'amqp/boilerplate' 
     | 
|
| 
       5 
5 
     | 
    
         
             
            RSpec.configure do |c|
         
     | 
| 
       6 
6 
     | 
    
         
             
              c.mock_with :rspec
         
     | 
| 
       7 
7 
     | 
    
         
             
            end
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            # "Test" consumers
         
     | 
| 
      
 10 
     | 
    
         
            +
            class FooConsumer < AMQP::Boilerplate::Consumer
         
     | 
| 
      
 11 
     | 
    
         
            +
              amqp_queue
         
     | 
| 
      
 12 
     | 
    
         
            +
            end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            class BarConsumer < AMQP::Boilerplate::Consumer
         
     | 
| 
      
 15 
     | 
    
         
            +
              amqp_queue "queue.name.here", :durable => true
         
     | 
| 
      
 16 
     | 
    
         
            +
              amqp_subscription :ack => true
         
     | 
| 
      
 17 
     | 
    
         
            +
            end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
            # "Test" producers
         
     | 
| 
      
 20 
     | 
    
         
            +
            class FooProducer
         
     | 
| 
      
 21 
     | 
    
         
            +
              extend AMQP::Boilerplate::Producer
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
              amqp :routing_key => "another.routing.key"
         
     | 
| 
      
 24 
     | 
    
         
            +
              amqp_message :some_method
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
              def some_method
         
     | 
| 
      
 27 
     | 
    
         
            +
                'Foo Bar'
         
     | 
| 
      
 28 
     | 
    
         
            +
              end
         
     | 
| 
      
 29 
     | 
    
         
            +
            end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
            class BarProducer
         
     | 
| 
      
 32 
     | 
    
         
            +
              extend AMQP::Boilerplate::Producer
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
              amqp :routing_key => "some.routing.key"
         
     | 
| 
      
 35 
     | 
    
         
            +
              amqp_exchange :fanout, "amq.fanout", { :durable => true }
         
     | 
| 
      
 36 
     | 
    
         
            +
              amqp_message :message
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
              def message
         
     | 
| 
      
 39 
     | 
    
         
            +
                "hello world!"
         
     | 
| 
      
 40 
     | 
    
         
            +
              end
         
     | 
| 
      
 41 
     | 
    
         
            +
            end
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,13 +1,13 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification 
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: amqp-boilerplate
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version 
         
     | 
| 
       4 
     | 
    
         
            -
              hash:  
     | 
| 
      
 4 
     | 
    
         
            +
              hash: 27
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
              segments: 
         
     | 
| 
       7 
7 
     | 
    
         
             
              - 0
         
     | 
| 
       8 
8 
     | 
    
         
             
              - 0
         
     | 
| 
       9 
     | 
    
         
            -
              -  
     | 
| 
       10 
     | 
    
         
            -
              version: 0.0. 
     | 
| 
      
 9 
     | 
    
         
            +
              - 2
         
     | 
| 
      
 10 
     | 
    
         
            +
              version: 0.0.2
         
     | 
| 
       11 
11 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       12 
12 
     | 
    
         
             
            authors: 
         
     | 
| 
       13 
13 
     | 
    
         
             
            - Patrick Baselier
         
     | 
| 
         @@ -16,7 +16,7 @@ autorequire: 
     | 
|
| 
       16 
16 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       17 
17 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
            date: 2011-09- 
     | 
| 
      
 19 
     | 
    
         
            +
            date: 2011-09-13 00:00:00 +02:00
         
     | 
| 
       20 
20 
     | 
    
         
             
            default_executable: 
         
     | 
| 
       21 
21 
     | 
    
         
             
            dependencies: 
         
     | 
| 
       22 
22 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     | 
| 
         @@ -49,10 +49,25 @@ dependencies: 
     | 
|
| 
       49 
49 
     | 
    
         
             
                    version: "2.6"
         
     | 
| 
       50 
50 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       51 
51 
     | 
    
         
             
              requirement: *id002
         
     | 
| 
      
 52 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency 
         
     | 
| 
      
 53 
     | 
    
         
            +
              name: yard
         
     | 
| 
      
 54 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 55 
     | 
    
         
            +
              version_requirements: &id003 !ruby/object:Gem::Requirement 
         
     | 
| 
      
 56 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 57 
     | 
    
         
            +
                requirements: 
         
     | 
| 
      
 58 
     | 
    
         
            +
                - - ~>
         
     | 
| 
      
 59 
     | 
    
         
            +
                  - !ruby/object:Gem::Version 
         
     | 
| 
      
 60 
     | 
    
         
            +
                    hash: 5
         
     | 
| 
      
 61 
     | 
    
         
            +
                    segments: 
         
     | 
| 
      
 62 
     | 
    
         
            +
                    - 0
         
     | 
| 
      
 63 
     | 
    
         
            +
                    - 7
         
     | 
| 
      
 64 
     | 
    
         
            +
                    version: "0.7"
         
     | 
| 
      
 65 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 66 
     | 
    
         
            +
              requirement: *id003
         
     | 
| 
       52 
67 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     | 
| 
       53 
68 
     | 
    
         
             
              name: amqp
         
     | 
| 
       54 
69 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       55 
     | 
    
         
            -
              version_requirements: & 
     | 
| 
      
 70 
     | 
    
         
            +
              version_requirements: &id004 !ruby/object:Gem::Requirement 
         
     | 
| 
       56 
71 
     | 
    
         
             
                none: false
         
     | 
| 
       57 
72 
     | 
    
         
             
                requirements: 
         
     | 
| 
       58 
73 
     | 
    
         
             
                - - ~>
         
     | 
| 
         @@ -63,7 +78,7 @@ dependencies: 
     | 
|
| 
       63 
78 
     | 
    
         
             
                    - 8
         
     | 
| 
       64 
79 
     | 
    
         
             
                    version: "0.8"
         
     | 
| 
       65 
80 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       66 
     | 
    
         
            -
              requirement: * 
     | 
| 
      
 81 
     | 
    
         
            +
              requirement: *id004
         
     | 
| 
       67 
82 
     | 
    
         
             
            description: Collection of modules that aid in setting up AMQP producers and consumers.
         
     | 
| 
       68 
83 
     | 
    
         
             
            email: 
         
     | 
| 
       69 
84 
     | 
    
         
             
            - patrick@kabisa.nl
         
     | 
| 
         @@ -84,13 +99,16 @@ files: 
     | 
|
| 
       84 
99 
     | 
    
         
             
            - lib/amqp-boilerplate.rb
         
     | 
| 
       85 
100 
     | 
    
         
             
            - lib/amqp/boilerplate.rb
         
     | 
| 
       86 
101 
     | 
    
         
             
            - lib/amqp/boilerplate/consumer.rb
         
     | 
| 
      
 102 
     | 
    
         
            +
            - lib/amqp/boilerplate/consumer_registry.rb
         
     | 
| 
       87 
103 
     | 
    
         
             
            - lib/amqp/boilerplate/logging.rb
         
     | 
| 
       88 
104 
     | 
    
         
             
            - lib/amqp/boilerplate/producer.rb
         
     | 
| 
       89 
105 
     | 
    
         
             
            - lib/amqp/boilerplate/version.rb
         
     | 
| 
      
 106 
     | 
    
         
            +
            - spec/amqp/boilerplate/consumer_registry_spec.rb
         
     | 
| 
       90 
107 
     | 
    
         
             
            - spec/amqp/boilerplate/consumer_spec.rb
         
     | 
| 
       91 
108 
     | 
    
         
             
            - spec/amqp/boilerplate/logging_spec.rb
         
     | 
| 
       92 
109 
     | 
    
         
             
            - spec/amqp/boilerplate/producer_spec.rb
         
     | 
| 
       93 
110 
     | 
    
         
             
            - spec/amqp/boilerplate_spec.rb
         
     | 
| 
      
 111 
     | 
    
         
            +
            - spec/fixtures/consumers/dummy_consumer.rb
         
     | 
| 
       94 
112 
     | 
    
         
             
            - spec/spec_helper.rb
         
     | 
| 
       95 
113 
     | 
    
         
             
            has_rdoc: true
         
     | 
| 
       96 
114 
     | 
    
         
             
            homepage: ""
         
     | 
| 
         @@ -127,8 +145,10 @@ signing_key: 
     | 
|
| 
       127 
145 
     | 
    
         
             
            specification_version: 3
         
     | 
| 
       128 
146 
     | 
    
         
             
            summary: Helper modules for quickly setting up AMQP producers/consumers
         
     | 
| 
       129 
147 
     | 
    
         
             
            test_files: 
         
     | 
| 
      
 148 
     | 
    
         
            +
            - spec/amqp/boilerplate/consumer_registry_spec.rb
         
     | 
| 
       130 
149 
     | 
    
         
             
            - spec/amqp/boilerplate/consumer_spec.rb
         
     | 
| 
       131 
150 
     | 
    
         
             
            - spec/amqp/boilerplate/logging_spec.rb
         
     | 
| 
       132 
151 
     | 
    
         
             
            - spec/amqp/boilerplate/producer_spec.rb
         
     | 
| 
       133 
152 
     | 
    
         
             
            - spec/amqp/boilerplate_spec.rb
         
     | 
| 
      
 153 
     | 
    
         
            +
            - spec/fixtures/consumers/dummy_consumer.rb
         
     | 
| 
       134 
154 
     | 
    
         
             
            - spec/spec_helper.rb
         
     |