Class: StagedEvent::GooglePubSub::Publisher
- Defined in:
- lib/staged_event/google_pub_sub/publisher.rb
Instance Method Summary collapse
-
#initialize ⇒ Publisher
constructor
A new instance of Publisher.
- #publish(model) ⇒ Object
Constructor Details
#initialize ⇒ Publisher
Returns a new instance of Publisher.
6 7 8 9 10 |
# File 'lib/staged_event/google_pub_sub/publisher.rb', line 6 def initialize @google_pubsub = Helper.new_google_pubsub raise ArgumentError, "topic_map must be initialized" unless topic_map.is_a?(Hash) && topic_map.any? end |
Instance Method Details
#publish(model) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/staged_event/google_pub_sub/publisher.rb', line 12 def publish(model) topic_name = model.topic || topic_map.keys.first topic_id = topic_map.fetch(topic_name) google_topic = google_pubsub.topic(topic_id, skip_lookup: true) # https://github.com/googleapis/google-cloud-ruby/blob/720d14d3641a60c0fab0bf8519bdd730a753a897/google-cloud-pubsub/lib/google/cloud/pubsub/topic.rb#L655 google_topic.publish(model.data) end |