lib/isimud/bunny_client.rb
def subscribe(queue, options = {}, &block)
      queue.subscribe(options.merge(manual_ack: true)) do |delivery_info, properties, payload|
        current_channel = delivery_info.channel
        begin
          log "Isimud: queue #{queue.name} received #{properties[:message_id]} routing_key: #{delivery_info.routing_key}", :debug
          Thread.current['isimud_queue_name']    = queue.name
          Thread.current['isimud_delivery_info'] = delivery_info
          Thread.current['isimud_properties']    = properties
          block.call(payload)
          if current_channel.open?
            log "Isimud: queue #{queue.name} finished with #{properties[:message_id]}, acknowledging", :debug
            current_channel.ack(delivery_info.delivery_tag)
          else
            log "Isimud: queue #{queue.name} unable to acknowledge #{properties[:message_id]}", :warn
          end
        rescue => e
          log("Isimud: queue #{queue.name} error processing #{properties[:message_id]} payload #{payload.inspect}: #{e.class.name} #{e.message}\n  #{e.backtrace.join("\n  ")}", :warn)
          retry_status = run_exception_handlers(e)
          log "Isimud: rejecting #{properties[:message_id]} requeue=#{retry_status}", :warn
          current_channel.open? && current_channel.reject(delivery_info.delivery_tag, retry_status)
        end
      end
    end
def subscribe(queue, options = {}, &block)
      queue.subscribe(options.merge(manual_ack: true)) do |delivery_info, properties, payload|
        current_channel = delivery_info.channel
        begin
          log "Isimud: queue #{queue.name} received #{properties[:message_id]} routing_key: #{delivery_info.routing_key}", :debug
          Thread.current['isimud_queue_name']    = queue.name
          Thread.current['isimud_delivery_info'] = delivery_info
          Thread.current['isimud_properties']    = properties
          block.call(payload)
          if current_channel.open?
            log "Isimud: queue #{queue.name} finished with #{properties[:message_id]}, acknowledging", :debug
            current_channel.ack(delivery_info.delivery_tag)
          else
            log "Isimud: queue #{queue.name} unable to acknowledge #{properties[:message_id]}", :warn
          end
        rescue => e
          log("Isimud: queue #{queue.name} error processing #{properties[:message_id]} payload #{payload.inspect}: #{e.class.name} #{e.message}\n  #{e.backtrace.join("\n  ")}", :warn)
          retry_status = run_exception_handlers(e)
          log "Isimud: rejecting #{properties[:message_id]} requeue=#{retry_status}", :warn
          current_channel.open? && current_channel.reject(delivery_info.delivery_tag, retry_status)
        end
      end
    end
Subscribe to messages on the Bunny queue. The provided block will be called each time a message is received.
   The message will be acknowledged and deleted from the queue unless an exception is raised from the block.
   In the case that an uncaught exception is raised, the message is rejected, and any declared exception handlers
   will be called.

 @param [Bunny::Queue] queue Bunny queue
 @param [Hash] options {} subscription options -- @see Bunny::Queue#subscribe
 @yieldparam [String] payload message text