Class: EventQ::Amazon::SubscriptionManager
- Inherits:
-
Object
- Object
- EventQ::Amazon::SubscriptionManager
- Defined in:
- lib/eventq_aws/aws_subscription_manager.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ SubscriptionManager
constructor
A new instance of SubscriptionManager.
- #subscribe(event_type, queue) ⇒ Object
- #unsubscribe(queue) ⇒ Object
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() if [:client] == nil raise "[#{self.class}] - :client (QueueClient) must be specified." end @client = [:client] if [:queue_manager] == nil raise "[#{self.class}] - :queue_manager (QueueManager) must be specified." end @manager = [: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 57 58 59 60 |
# File 'lib/eventq_aws/aws_subscription_manager.rb', line 20 def subscribe(event_type, queue) _event_type = EventQ.create_event_type(event_type) 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 + '", "Condition" : { "ArnEquals" : { "aws:SourceArn":"' + topic_arn + '" } } } ] }' } }) @client.sns.subscribe({ topic_arn: topic_arn, protocol: 'sqs'.freeze, endpoint: queue_arn }) return true end |
#unsubscribe(queue) ⇒ Object
62 63 64 65 66 |
# File 'lib/eventq_aws/aws_subscription_manager.rb', line 62 def unsubscribe(queue) raise "[#{self.class}] - Not implemented. Please unsubscribe the queue from the topic inside the AWS Management Console." end |