Class: EventQ::Amazon::QueueClient
- Inherits:
-
Object
- Object
- EventQ::Amazon::QueueClient
- Defined in:
- lib/eventq_aws/aws_queue_client.rb
Instance Method Summary collapse
- #aws_safe_name(name) ⇒ Object
- #create_topic_arn(event_type) ⇒ Object
- #get_queue_arn(queue) ⇒ Object
-
#get_queue_url(queue) ⇒ Object
Returns the URL of the queue.
- #get_topic_arn(event_type) ⇒ Object
-
#initialize(options = {}) ⇒ QueueClient
constructor
A new instance of QueueClient.
-
#sns ⇒ Object
Returns the AWS SNS Client.
-
#sqs ⇒ Object
Returns the AWS SQS Client.
Constructor Details
#initialize(options = {}) ⇒ QueueClient
Returns a new instance of QueueClient.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/eventq_aws/aws_queue_client.rb', line 5 def initialize( = {}) if .has_key?(:aws_key) Aws.config[:credentials] = Aws::Credentials.new([:aws_key], [:aws_secret]) end if !.has_key?(:aws_account_number) raise ':aws_account_number option must be specified.'.freeze end @aws_account = [:aws_account_number] if .has_key?(:aws_region) @aws_region = [:aws_region] Aws.config[:region] = @aws_region else @aws_region = Aws.config[:region] end end |
Instance Method Details
#aws_safe_name(name) ⇒ Object
62 63 64 |
# File 'lib/eventq_aws/aws_queue_client.rb', line 62 def aws_safe_name(name) return name[0..79].gsub(/[^a-zA-Z\d_\-]/,'') end |
#create_topic_arn(event_type) ⇒ Object
44 45 46 47 48 |
# File 'lib/eventq_aws/aws_queue_client.rb', line 44 def create_topic_arn(event_type) _event_type = EventQ.create_event_type(event_type) response = sns.create_topic(name: aws_safe_name(_event_type)) return response.topic_arn end |
#get_queue_arn(queue) ⇒ Object
39 40 41 42 |
# File 'lib/eventq_aws/aws_queue_client.rb', line 39 def get_queue_arn(queue) _queue_name = EventQ.create_queue_name(queue.name) return "arn:aws:sqs:#{@aws_region}:#{@aws_account}:#{aws_safe_name(_queue_name)}" end |
#get_queue_url(queue) ⇒ Object
Returns the URL of the queue. The queue will be created when it does
53 54 55 56 57 58 59 60 |
# File 'lib/eventq_aws/aws_queue_client.rb', line 53 def get_queue_url(queue) _queue_name = EventQ.create_queue_name(queue.name) response= sqs.get_queue_url( queue_name: aws_safe_name(_queue_name), queue_owner_aws_account_id: @aws_account, ) return response.queue_url end |
#get_topic_arn(event_type) ⇒ Object
34 35 36 37 |
# File 'lib/eventq_aws/aws_queue_client.rb', line 34 def get_topic_arn(event_type) _event_type = EventQ.create_event_type(event_type) return "arn:aws:sns:#{@aws_region}:#{@aws_account}:#{aws_safe_name(_event_type)}" end |
#sns ⇒ Object
Returns the AWS SNS Client
30 31 32 |
# File 'lib/eventq_aws/aws_queue_client.rb', line 30 def sns @sns ||= Aws::SNS::Client.new end |
#sqs ⇒ Object
Returns the AWS SQS Client
25 26 27 |
# File 'lib/eventq_aws/aws_queue_client.rb', line 25 def sqs @sqs ||= Aws::SQS::Client.new end |