Guest User

Untitled

a guest
Jul 25th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. # frozen_string_literal: true
  2.  
  3. require 'pubbit'
  4.  
  5. module Publisher
  6. class Exchange
  7. def self.publish(event)
  8. new('school_api.updates').publish(event)
  9. end
  10.  
  11. def initialize(routing_key)
  12. @publisher = initialize_publisher(routing_key)
  13. declare_exchange
  14. end
  15.  
  16. def publish(event)
  17. @publisher.publish(event)
  18. rescue Pubbit::Error => e
  19. ErrorLogger.log_exception(e)
  20. end
  21.  
  22. private
  23.  
  24. def initialize_publisher(routing_key)
  25. Pubbit::Publisher.new(
  26. amqp: {
  27. url: Rails.configuration.rabbitmq[:base_url],
  28. username: Rails.configuration.rabbitmq[:username],
  29. password: Rails.configuration.rabbitmq[:password],
  30. vhost: '/',
  31. exchange: 'school-api',
  32. routing_key: routing_key
  33. }
  34. )
  35. end
  36.  
  37. def declare_exchange
  38. @publisher.declare_exchange
  39. rescue ::Pubbit::Error => e
  40. ErrorLogger.log_exception(e)
  41. end
  42. end
  43. end
Add Comment
Please, Sign In to add comment