Class: EventQ::Amazon::SubscriptionManager
- Inherits:
-
Object
- Object
- EventQ::Amazon::SubscriptionManager
- Defined in:
- lib/eventq/eventq_aws/aws_subscription_manager.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ SubscriptionManager
constructor
A new instance of SubscriptionManager.
- #subscribe(event_type, queue, topic_region = nil, queue_region = nil) ⇒ Object
- #unsubscribe(_queue) ⇒ Object
Constructor Details
#initialize(options) ⇒ SubscriptionManager
Returns a new instance of SubscriptionManager.
6 7 8 9 10 11 12 13 |
# File 'lib/eventq/eventq_aws/aws_subscription_manager.rb', line 6 def initialize() mandatory = %i[client queue_manager] missing = mandatory - .keys raise "[#{self.class}] - Missing options #{missing} must be specified." unless missing.empty? @client = [:client] @manager = [:queue_manager] end |
Instance Method Details
#subscribe(event_type, queue, topic_region = nil, queue_region = nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/eventq/eventq_aws/aws_subscription_manager.rb', line 15 def subscribe(event_type, queue, topic_region = nil, queue_region = nil) if queue.isolated method = :get_topic_arn else method = :create_topic_arn end topic_arn = @client.sns_helper(topic_region).public_send(method, event_type, topic_region) raise Exceptions::EventTypeNotFound, 'SNS topic not found, unable to subscribe' unless topic_arn q = @manager.get_queue(queue) queue_arn = @client.sqs_helper(queue_region).get_queue_arn(queue) attributes = default_queue_attributes(q, queue_arn) @client.sqs(queue_region).set_queue_attributes(attributes) # skip subscribe if subscription for given queue/topic already exists # this fixes a localstack issue: https://github.com/localstack/localstack/issues/933 return true if existing_subscription?(queue_arn, topic_arn) @client.sns(topic_region).subscribe( topic_arn: topic_arn, protocol: 'sqs', endpoint: queue_arn ) EventQ.logger.debug do "[#{self.class} #subscribe] - Subscribing Queue: #{queue.name} to topic_arn: #{topic_arn}, endpoint: #{queue_arn}" end true end |
#unsubscribe(_queue) ⇒ Object
48 49 50 |
# File 'lib/eventq/eventq_aws/aws_subscription_manager.rb', line 48 def unsubscribe(_queue) raise "[#{self.class}] - Not implemented. Please unsubscribe the queue from the topic inside the AWS Management Console." end |