Class: Artsy::EventService::Publisher
- Inherits:
-
Object
- Object
- Artsy::EventService::Publisher
- Defined in:
- lib/artsy-eventservice/artsy/event_service/publisher.rb
Class Method Summary collapse
- .publish_data(topic:, data:, routing_key: nil) ⇒ Object
- .publish_event(topic:, event:, routing_key: nil) ⇒ Object
Instance Method Summary collapse
- #config ⇒ Object
- #post_data(topic:, data:, routing_key: nil) ⇒ Object
- #post_event(topic:, event:, routing_key: nil) ⇒ Object
Class Method Details
.publish_data(topic:, data:, routing_key: nil) ⇒ Object
9 10 11 |
# File 'lib/artsy-eventservice/artsy/event_service/publisher.rb', line 9 def self.publish_data(topic:, data:, routing_key: nil) new.post_data(topic: topic, data: data, routing_key: routing_key) end |
.publish_event(topic:, event:, routing_key: nil) ⇒ Object
5 6 7 |
# File 'lib/artsy-eventservice/artsy/event_service/publisher.rb', line 5 def self.publish_event(topic:, event:, routing_key: nil) new.post_event(topic: topic, event: event, routing_key: routing_key) end |
Instance Method Details
#config ⇒ Object
36 37 38 |
# File 'lib/artsy-eventservice/artsy/event_service/publisher.rb', line 36 def config Artsy::EventService.config end |
#post_data(topic:, data:, routing_key: nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/artsy-eventservice/artsy/event_service/publisher.rb', line 13 def post_data(topic:, data:, routing_key: nil) RabbitMQConnection.get_channel do |channel| channel.confirm_select if config.confirms_enabled exchange = channel.topic(topic, durable: true) exchange.publish( data, routing_key: routing_key, persistent: true, content_type: 'application/json', app_id: config.app_name ) raise 'Publishing data failed' if config.confirms_enabled && !channel.wait_for_confirms end end |
#post_event(topic:, event:, routing_key: nil) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/artsy-eventservice/artsy/event_service/publisher.rb', line 28 def post_event(topic:, event:, routing_key: nil) raise 'Event missing topic or verb.' if event.verb.to_s.empty? || topic.to_s.empty? post_data( topic: topic, data: event.json, routing_key: routing_key || event.verb) end |