Created
July 25, 2018 14:13
-
-
Save iftheshoefritz/3c362854a16a8a0e74f52e3a44444d15 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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