Class: SimpleMessaging::MessageQueue::SQS

Inherits:
SimpleMessaging::MessageQueue show all
Defined in:
lib/simple_messaging/message_queue/sqs.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from SimpleMessaging::MessageQueue

driver_name, driver_name=, instance, unregister_queue

Constructor Details

#initialize(name) ⇒ SQS

Returns a new instance of SQS.



9
10
11
12
13
# File 'lib/simple_messaging/message_queue/sqs.rb', line 9

def initialize(name)
  @sqs = Aws::SQS::Client.new
  @queue_url = @sqs.create_queue(queue_name: queue_name(name.to_s)).queue_url
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/simple_messaging/message_queue/sqs.rb', line 7

def name
  @name
end

Instance Method Details

#deleteObject



31
32
33
34
# File 'lib/simple_messaging/message_queue/sqs.rb', line 31

def delete
  MessageQueue.unregister_queue(name)
  @queue.delete
end

#enqueue(message) ⇒ Object



15
16
17
# File 'lib/simple_messaging/message_queue/sqs.rb', line 15

def enqueue(message)
  @sqs.send_message(queue_url: @queue_url, message_body: message)
end

#poll(&block) ⇒ Object



24
25
26
27
28
29
# File 'lib/simple_messaging/message_queue/sqs.rb', line 24

def poll(&block)
  poller = Aws::SQS::QueuePoller.new(@queue_url)
  poller.poll do |message|
    yield message.body
  end
end

#pop {|response.messages.first.body| ... } ⇒ Object

Yields:

  • (response.messages.first.body)


19
20
21
22
# File 'lib/simple_messaging/message_queue/sqs.rb', line 19

def pop(&block)
  response = @sqs.receive_message(queue_url: @queue_url)
  yield response.messages.first.body
end