Class: BetterSqs::Client
- Inherits:
-
Object
- Object
- BetterSqs::Client
- Defined in:
- lib/better_sqs/client.rb
Overview
A class that wraps the aws sdk v2 SQS client to reduce interface complexity
Instance Attribute Summary collapse
-
#sqs ⇒ Aws::SQS::Client
Get the existing or create a new instances of the SQS client.
Instance Method Summary collapse
-
#defer_retry(message) ⇒ Object
Updates the message visibility timeout to create some delay before an attempt will be made to reprocess the message.
-
#delete(message) ⇒ Object
Delete a message from the queue.
-
#initialize ⇒ Client
constructor
A new instance of Client.
-
#push(queue_name, message_body) ⇒ Types::SendMessageResult
Push a message onto a queue.
-
#reserve(queue_name) ⇒ Messages::Sqs, NilClass
Reserve a message from the specified queue.
-
#url_for_queue(queue_name) ⇒ AWS::SQS::Queue
Get the specified queue instance if it already exists, otherwise create it and wait for it to be readied.
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
7 8 9 10 |
# File 'lib/better_sqs/client.rb', line 7 def initialize # if BetterSqs has not been configured then run the default configuration BetterSqs.configure unless BetterSqs.configured? end |
Instance Attribute Details
#sqs ⇒ Aws::SQS::Client
Get the existing or create a new instances of the SQS client
52 53 54 |
# File 'lib/better_sqs/client.rb', line 52 def sqs @sqs end |
Instance Method Details
#defer_retry(message) ⇒ Object
Updates the message visibility timeout to create some delay before an attempt will be made to reprocess the
43 44 45 46 47 |
# File 'lib/better_sqs/client.rb', line 43 def defer_retry() sqs. queue_url: url_for_queue(.queue), receipt_handle: .receipt_handle, visibility_timeout: BetterSqs.configuration. end |
#delete(message) ⇒ Object
Delete a message from the queue
35 36 37 |
# File 'lib/better_sqs/client.rb', line 35 def delete() sqs. queue_url: url_for_queue(.queue), receipt_handle: .receipt_handle end |
#push(queue_name, message_body) ⇒ Types::SendMessageResult
Push a message onto a queue
18 19 20 |
# File 'lib/better_sqs/client.rb', line 18 def push(queue_name, ) sqs.(queue_url: url_for_queue(queue_name), message_body: ) end |
#reserve(queue_name) ⇒ Messages::Sqs, NilClass
Reserve a message from the specified queue
26 27 28 29 30 |
# File 'lib/better_sqs/client.rb', line 26 def reserve(queue_name) resp = sqs.(queue_url: url_for_queue(queue_name), max_number_of_messages: 1) return nil unless resp..any? Message.new queue_client: self, queue: queue_name, sqs_message: resp..first end |
#url_for_queue(queue_name) ⇒ AWS::SQS::Queue
Get the specified queue instance if it already exists, otherwise create it and wait for it to be readied
60 61 62 |
# File 'lib/better_sqs/client.rb', line 60 def url_for_queue(queue_name) sqs.create_queue(queue_name: queue_name).queue_url end |