Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 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
Add Comment
Please, Sign In to add comment