Class: SimpleMessaging::MessageQueue::SQS
Instance Attribute Summary collapse
Instance Method Summary
collapse
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
#name ⇒ Object
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
#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
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
|