Class: Realm::SNS::Gateway::TopicAdapter
- Inherits:
-
Object
- Object
- Realm::SNS::Gateway::TopicAdapter
- Defined in:
- lib/realm/sns/gateway/topic_adapter.rb
Overview
Provides cleaner SDK over Aws::SNS::Topic
Defined Under Namespace
Classes: SubscriptionError
Instance Method Summary collapse
-
#initialize(topic_or_arn) ⇒ TopicAdapter
constructor
A new instance of TopicAdapter.
- #publish(event_type, message) ⇒ Object
- #subscribe(event_type, queue) ⇒ Object
Constructor Details
#initialize(topic_or_arn) ⇒ TopicAdapter
Returns a new instance of TopicAdapter.
14 15 16 |
# File 'lib/realm/sns/gateway/topic_adapter.rb', line 14 def initialize(topic_or_arn) @topic = topic_or_arn.is_a?(Aws::SNS::Topic) ? topic_or_arn : Aws::SNS::Resource.new.topic(topic_or_arn) end |
Instance Method Details
#publish(event_type, message) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/realm/sns/gateway/topic_adapter.rb', line 18 def publish(event_type, ) @topic.publish( message: , message_attributes: { 'event_type' => { data_type: 'String', string_value: event_type.to_s } }, ) end |
#subscribe(event_type, queue) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/realm/sns/gateway/topic_adapter.rb', line 25 def subscribe(event_type, queue) queue.(@topic.arn) attributes = subscribe_attributes(event_type) @topic.subscribe(protocol: 'sqs', endpoint: queue.arn, attributes: attributes) rescue Aws::SNS::Errors::InvalidParameter raise SubscriptionError.new(queue.arn, attributes) end |