Module: SQS

Extended by:
SQS
Included in:
SQS
Defined in:
lib/sqs_cli/sqs.rb

Instance Method Summary collapse

Instance Method Details

#all_queuesObject



6
7
8
# File 'lib/sqs_cli/sqs.rb', line 6

def all_queues
  sqs.list_queues.queue_urls
end

#delete_message_batch(queue_url, batch) ⇒ Object



29
30
31
32
33
34
# File 'lib/sqs_cli/sqs.rb', line 29

def delete_message_batch(queue_url, batch)
  entries = batch.map do |m|
    { id: m.message_id, receipt_handle: m.receipt_handle }
  end
  sqs.delete_message_batch(queue_url: queue_url, entries: entries)
end

#read_message_batches(queue_url, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/sqs_cli/sqs.rb', line 10

def read_message_batches(queue_url, &block)
  loop do
    resp = sqs.receive_message(
      queue_url: queue_url,
      max_number_of_messages: 10,
      visibility_timeout: 10
    )
    break if resp.messages.empty?
    block.call resp.messages
  end
end

#send_message_batch(queue_url, batch) ⇒ Object



22
23
24
25
26
27
# File 'lib/sqs_cli/sqs.rb', line 22

def send_message_batch(queue_url, batch)
  entries = batch.map do |msg|
    { id: msg.message_id, message_body: msg.body }
  end
  sqs.send_message_batch(queue_url: queue_url, entries: entries)
end