Class: Propono::QueueSubscription

Inherits:
Object
  • Object
show all
Includes:
Sns, Sqs
Defined in:
lib/propono/components/queue_subscription.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(topic_id, options = {}) ⇒ QueueSubscription

Returns a new instance of QueueSubscription.



15
16
17
18
19
20
# File 'lib/propono/components/queue_subscription.rb', line 15

def initialize(topic_id, options = {})
  @topic_id = topic_id
  @suffixed_topic_id = "#{topic_id}#{Propono.config.queue_suffix}"
  @suffixed_slow_topic_id = "#{topic_id}#{Propono.config.queue_suffix}-slow"
  @queue_name = "#{Propono.config.application_name.gsub(" ", "_")}-#{@suffixed_topic_id}"
end

Instance Attribute Details

#corrupt_queueObject (readonly)

Returns the value of attribute corrupt_queue.



7
8
9
# File 'lib/propono/components/queue_subscription.rb', line 7

def corrupt_queue
  @corrupt_queue
end

#failed_queueObject (readonly)

Returns the value of attribute failed_queue.



7
8
9
# File 'lib/propono/components/queue_subscription.rb', line 7

def failed_queue
  @failed_queue
end

#queueObject (readonly)

Returns the value of attribute queue.



7
8
9
# File 'lib/propono/components/queue_subscription.rb', line 7

def queue
  @queue
end

#queue_nameObject (readonly)

Returns the value of attribute queue_name.



7
8
9
# File 'lib/propono/components/queue_subscription.rb', line 7

def queue_name
  @queue_name
end

#slow_queueObject (readonly)

Returns the value of attribute slow_queue.



7
8
9
# File 'lib/propono/components/queue_subscription.rb', line 7

def slow_queue
  @slow_queue
end

#topic_arnObject (readonly)

Returns the value of attribute topic_arn.



7
8
9
# File 'lib/propono/components/queue_subscription.rb', line 7

def topic_arn
  @topic_arn
end

Class Method Details

.create(topic_id, options = {}) ⇒ Object



9
10
11
12
13
# File 'lib/propono/components/queue_subscription.rb', line 9

def self.create(topic_id, options = {})
  new(topic_id, options).tap do |subscription|
    subscription.create
  end
end

Instance Method Details

#createObject

Raises:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/propono/components/queue_subscription.rb', line 22

def create
  raise ProponoError.new("topic_id is nil") unless @topic_id
  @topic = TopicCreator.find_or_create(@suffixed_topic_id)
  @queue = QueueCreator.find_or_create(queue_name)
  @failed_queue = QueueCreator.find_or_create("#{queue_name}-failed")
  @corrupt_queue = QueueCreator.find_or_create("#{queue_name}-corrupt")
  sns.subscribe(@topic.arn, @queue.arn, 'sqs')
  sqs.set_queue_attributes(@queue.url, "Policy", generate_policy(@queue, @topic))

  @slow_queue = QueueCreator.find_or_create("#{queue_name}-slow")
  @slow_topic = TopicCreator.find_or_create(@suffixed_slow_topic_id)
  sns.subscribe(@slow_topic.arn, @slow_queue.arn, 'sqs')
  sqs.set_queue_attributes(@slow_queue.url, "Policy", generate_policy(@slow_queue, @slow_topic))
end