Skip to content

Instantly share code, notes, and snippets.

@iftheshoefritz
Created July 25, 2018 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iftheshoefritz/3c362854a16a8a0e74f52e3a44444d15 to your computer and use it in GitHub Desktop.
Save iftheshoefritz/3c362854a16a8a0e74f52e3a44444d15 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
require 'pubbit'
module Publisher
class Exchange
def self.publish(event)
new('school_api.updates').publish(event)
end
def initialize(routing_key)
@publisher = initialize_publisher(routing_key)
declare_exchange
end
def publish(event)
@publisher.publish(event)
rescue Pubbit::Error => e
ErrorLogger.log_exception(e)
end
private
def initialize_publisher(routing_key)
Pubbit::Publisher.new(
amqp: {
url: Rails.configuration.rabbitmq[:base_url],
username: Rails.configuration.rabbitmq[:username],
password: Rails.configuration.rabbitmq[:password],
vhost: '/',
exchange: 'school-api',
routing_key: routing_key
}
)
end
def declare_exchange
@publisher.declare_exchange
rescue ::Pubbit::Error => e
ErrorLogger.log_exception(e)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment