Class: Propono::AwsClient
- Inherits:
-
Object
- Object
- Propono::AwsClient
- Defined in:
- lib/propono/components/aws_client.rb
Instance Attribute Summary collapse
-
#aws_config ⇒ Object
readonly
Returns the value of attribute aws_config.
Instance Method Summary collapse
- #create_queue(name) ⇒ Object
- #create_topic(name) ⇒ Object
- #delete_from_sqs(queue, receipt_handle) ⇒ Object
-
#initialize(aws_config) ⇒ AwsClient
constructor
A new instance of AwsClient.
- #publish_to_sns(topic, message) ⇒ Object
- #read_from_sqs(queue, num_messages, long_poll: true, visibility_timeout: nil) ⇒ Object
- #send_to_sqs(queue, message) ⇒ Object
- #set_sqs_policy(queue, policy) ⇒ Object
- #subscribe_sqs_to_sns(queue, topic) ⇒ Object
Constructor Details
#initialize(aws_config) ⇒ AwsClient
Returns a new instance of AwsClient.
7 8 9 |
# File 'lib/propono/components/aws_client.rb', line 7 def initialize(aws_config) @aws_config = aws_config end |
Instance Attribute Details
#aws_config ⇒ Object (readonly)
Returns the value of attribute aws_config.
6 7 8 |
# File 'lib/propono/components/aws_client.rb', line 6 def aws_config @aws_config end |
Instance Method Details
#create_queue(name) ⇒ Object
29 30 31 32 33 |
# File 'lib/propono/components/aws_client.rb', line 29 def create_queue(name) url = sqs_client.create_queue(queue_name: name).queue_url attributes = sqs_client.get_queue_attributes(queue_url: url, attribute_names: ["QueueArn"]).attributes Queue.new(url, attributes) end |
#create_topic(name) ⇒ Object
25 26 27 |
# File 'lib/propono/components/aws_client.rb', line 25 def create_topic(name) Topic.new(sns_client.create_topic(name: name)) end |
#delete_from_sqs(queue, receipt_handle) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/propono/components/aws_client.rb', line 61 def delete_from_sqs(queue, receipt_handle) sqs_client.( queue_url: queue.url, receipt_handle: receipt_handle ) end |
#publish_to_sns(topic, message) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/propono/components/aws_client.rb', line 11 def publish_to_sns(topic, ) sns_client.publish( topic_arn: topic.arn, message: .to_json ) end |
#read_from_sqs(queue, num_messages, long_poll: true, visibility_timeout: nil) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/propono/components/aws_client.rb', line 50 def read_from_sqs(queue, , long_poll: true, visibility_timeout: nil) wait_time_seconds = long_poll ? 20 : 0 visibility_timeout ||= 30 sqs_client.( queue_url: queue.url, wait_time_seconds: wait_time_seconds, max_number_of_messages: , visibility_timeout: visibility_timeout ). end |
#send_to_sqs(queue, message) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/propono/components/aws_client.rb', line 18 def send_to_sqs(queue, ) sqs_client.( queue_url: queue.url, message_body: ) end |
#set_sqs_policy(queue, policy) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/propono/components/aws_client.rb', line 43 def set_sqs_policy(queue, policy) sqs_client.set_queue_attributes( queue_url: queue.url, attributes: { Policy: policy } ) end |
#subscribe_sqs_to_sns(queue, topic) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/propono/components/aws_client.rb', line 35 def subscribe_sqs_to_sns(queue, topic) sns_client.subscribe( topic_arn: topic.arn, protocol: 'sqs', endpoint: queue.arn ) end |