class Artsy::EventService::Publisher
Public Class Methods
publish_data(topic:, data:, routing_key: nil, headers: {})
click to toggle source
# File lib/artsy-eventservice/artsy/event_service/publisher.rb, line 9 def self.publish_data(topic:, data:, routing_key: nil, headers: {}) new.post_data(topic: topic, data: data, routing_key: routing_key, headers: headers) end
publish_event(topic:, event:, routing_key: nil, headers: {})
click to toggle source
# File lib/artsy-eventservice/artsy/event_service/publisher.rb, line 5 def self.publish_event(topic:, event:, routing_key: nil, headers: {}) new.post_event(topic: topic, event: event, routing_key: routing_key, headers: headers) end
Public Instance Methods
config()
click to toggle source
# File lib/artsy-eventservice/artsy/event_service/publisher.rb, line 39 def config Artsy::EventService.config end
post_data(topic:, data:, routing_key: nil, headers: {})
click to toggle source
# File lib/artsy-eventservice/artsy/event_service/publisher.rb, line 13 def post_data(topic:, data:, routing_key: nil, headers: {}) 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', headers: headers, 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, headers: {})
click to toggle source
# File lib/artsy-eventservice/artsy/event_service/publisher.rb, line 29 def post_event(topic:, event:, routing_key: nil, headers: {}) raise 'Event missing topic or verb.' if event.verb.to_s.empty? || topic.to_s.empty? post_data( topic: topic, data: event.to_json, routing_key: routing_key || event.verb, headers: headers ) end