Class: MicroQ::SqsClient
- Inherits:
-
Object
- Object
- MicroQ::SqsClient
- Defined in:
- lib/micro_q/sqs_client.rb
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(name) ⇒ SqsClient
constructor
A new instance of SqsClient.
- #messages ⇒ Object
- #messages_create(message) ⇒ Object
- #messages_delete(message) ⇒ Object
Constructor Details
#initialize(name) ⇒ SqsClient
Returns a new instance of SqsClient.
5 6 7 8 |
# File 'lib/micro_q/sqs_client.rb', line 5 def initialize(name) @name = "#{MicroQ.config.env}_#{name}" @url = client.create_queue(:queue_name => @name)[:queue_url] end |
Instance Attribute Details
#url ⇒ Object (readonly)
Returns the value of attribute url.
3 4 5 |
# File 'lib/micro_q/sqs_client.rb', line 3 def url @url end |
Instance Method Details
#messages ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/micro_q/sqs_client.rb', line 10 def response = client.( :queue_url => url, :wait_time_seconds => 10, :max_number_of_messages => 10, :visibility_timeout => 5 * 60 ) ((response && response[:messages]) || []).collect do || JSON.parse([:body]).merge( 'sqs_id' => [:message_id], 'sqs_handle' => [:receipt_handle], 'sqs_queue' => url ) end end |
#messages_create(message) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/micro_q/sqs_client.rb', line 27 def () attrs = { :queue_url => url, :message_body => .to_json } attrs[:delay_seconds] = (['run_at'].to_i - Time.now.to_i) if .key?('run_at') client.(attrs)[:message_id] end |
#messages_delete(message) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/micro_q/sqs_client.rb', line 38 def () client.( :queue_url => ['sqs_queue'], :receipt_handle => ['sqs_handle'] ) end |