Sha256: 78438f9b184296bffb239369415a129cdb1001411726c9e648e8f178119c5489
Contents?: true
Size: 1.01 KB
Versions: 1
Compression:
Stored size: 1.01 KB
Contents
module RisingDragon module SNS class Publisher attr_accessor :use_cache def initialize(sns_client) @sns_client = sns_client @topic_cache = {} @use_cache = true # default true :) end def send_event!(topic_name, event_type, data) event = create_event(event_type, data) topic = get_topic(topic_name) @sns_client.publish(topic_arn: topic.topic_arn, message: event.to_json) end private def create_event(type, data) ::RisingDragon::Event.new(id: uuid, timestamp: unixtime, type: type, data: data) end def uuid SecureRandom.uuid end def unixtime (Time.now.to_f * 1000).to_i end def get_topic(topic_name) return create_topic(topic_name) unless @use_cache @topic_cache[topic_name] ||= create_topic(topic_name) end def create_topic(topic_name) @sns_client.create_topic(name: topic_name) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rising_dragon-0.3.1 | lib/rising_dragon/sns/publisher.rb |