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
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.
10 11 12 |
# File 'lib/realm/sns/gateway/topic_adapter.rb', line 10 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
14 15 16 17 18 19 |
# File 'lib/realm/sns/gateway/topic_adapter.rb', line 14 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
21 22 23 24 25 26 27 28 |
# File 'lib/realm/sns/gateway/topic_adapter.rb', line 21 def subscribe(event_type, queue) queue.(@topic.arn) @topic.subscribe( protocol: 'sqs', endpoint: queue.arn, attributes: subscribe_attributes(event_type), ) end |