Class: TxghQueue::Backends::Sqs::Queue

Inherits:
Object
  • Object
show all
Defined in:
lib/txgh-queue/backends/sqs/queue.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Queue

Returns a new instance of Queue.



9
10
11
12
13
# File 'lib/txgh-queue/backends/sqs/queue.rb', line 9

def initialize(options = {})
  @name = options.fetch(:name)
  @region = options.fetch(:region)
  @events = options.fetch(:events, [])
end

Instance Attribute Details

#eventsObject (readonly)

Returns the value of attribute events.



7
8
9
# File 'lib/txgh-queue/backends/sqs/queue.rb', line 7

def events
  @events
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/txgh-queue/backends/sqs/queue.rb', line 7

def name
  @name
end

#regionObject (readonly)

Returns the value of attribute region.



7
8
9
# File 'lib/txgh-queue/backends/sqs/queue.rb', line 7

def region
  @region
end

Instance Method Details

#clientObject



15
16
17
# File 'lib/txgh-queue/backends/sqs/queue.rb', line 15

def client
  @client ||= Aws::SQS::Client.new(region: region)
end

#delete_message(receipt_handle) ⇒ Object



32
33
34
35
# File 'lib/txgh-queue/backends/sqs/queue.rb', line 32

def delete_message(receipt_handle)
  params = { queue_url: url, receipt_handle: receipt_handle }
  client.delete_message(params)
end

#receive_message(options = {}) ⇒ Object



23
24
25
# File 'lib/txgh-queue/backends/sqs/queue.rb', line 23

def receive_message(options = {})
  client.receive_message(options.merge(queue_url: url))
end

#send_message(body, options = {}) ⇒ Object



27
28
29
30
# File 'lib/txgh-queue/backends/sqs/queue.rb', line 27

def send_message(body, options = {})
  params = options.merge(message_body: body, queue_url: url)
  client.send_message(params)
end

#urlObject



19
20
21
# File 'lib/txgh-queue/backends/sqs/queue.rb', line 19

def url
  @url ||= client.get_queue_url(queue_name: name).queue_url
end