Class: EventQ::Amazon::SubscriptionManager

Inherits:
Object
  • Object
show all
Defined in:
lib/eventq_aws/aws_subscription_manager.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ SubscriptionManager

Returns a new instance of SubscriptionManager.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/eventq_aws/aws_subscription_manager.rb', line 5

def initialize(options)

  if options[:client] == nil
    raise "[#{self.class}] - :client (QueueClient) must be specified."
  end

  @client = options[:client]

  if options[:queue_manager] == nil
    raise "[#{self.class}] - :queue_manager (QueueManager) must be specified."
  end

  @manager = options[:queue_manager]
end

Instance Method Details

#subscribe(event_type, queue) ⇒ Object



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
47
48
49
50
51
52
53
54
55
56
# File 'lib/eventq_aws/aws_subscription_manager.rb', line 20

def subscribe(event_type, queue)

  topic_arn = @client.create_topic_arn(event_type)

  q = @manager.get_queue(queue)
  queue_arn = @client.get_queue_arn(queue)

  @client.sqs.set_queue_attributes({
                                       queue_url: q,
                                       attributes:{
                                           'Policy'.freeze => '{
  "Version": "2012-10-17",
  "Id": "SNStoSQS",
  "Statement": [
    {
"Sid":"rule1",
"Effect": "Allow",
"Principal": "*",
"Action": "sqs:*",
"Resource": "' + queue_arn + '"
    }
  ]
}'
                                       }
                                   })

  @client.sns.subscribe({
                            topic_arn: topic_arn,
                            protocol: 'sqs'.freeze,
                            endpoint: queue_arn
                        })
  EventQ.logger.debug do
    "[#{self.class} #subscribe] - Subscribing Queue: #{queue.name} to topic_arn: #{topic_arn}, endpoint: #{queue_arn}"
  end
  return true

end

#unsubscribe(queue) ⇒ Object



58
59
60
61
62
# File 'lib/eventq_aws/aws_subscription_manager.rb', line 58

def unsubscribe(queue)

  raise "[#{self.class}] - Not implemented. Please unsubscribe the queue from the topic inside the AWS Management Console."

end