Sha256: c22091fda6fc23b5ab59c52059e6b1515abfd52c585e315b0b9c91abe6ad0578

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

module FakeSQS
  module Actions
    class SendMessageBatch

      def initialize(options = {})
        @server    = options.fetch(:server)
        @queues    = options.fetch(:queues)
        @responder = options.fetch(:responder)
      end

      def call(queue_name, params)
        queue = @queues.get(queue_name)
        messages = params.select { |k,v| k =~ /SendMessageBatchRequestEntry\.\d+\.MessageBody/ }

        results = {}

        messages.each do |key, value|
          id = key.split('.')[1]
          msg_id = params.fetch("SendMessageBatchRequestEntry.#{id}.Id")
          delay = params["SendMessageBatchRequestEntry.#{id}.DelaySeconds"]
          message = queue.send_message("MessageBody" => value, "DelaySeconds" => delay)
          results[msg_id] = message
        end

        @responder.call :SendMessageBatch do |xml|
          results.each do |msg_id, message|
            xml.SendMessageBatchResultEntry do
              xml.Id msg_id
              xml.MessageId message.id
              xml.MD5OfMessageBody message.md5
            end
          end
        end
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fake_sqs-0.4.3 lib/fake_sqs/actions/send_message_batch.rb
fake_sqs-0.4.2 lib/fake_sqs/actions/send_message_batch.rb