Class: Happn::EventConsumer
- Inherits:
-
Object
- Object
- Happn::EventConsumer
- Defined in:
- lib/happn/event_consumer.rb
Instance Method Summary collapse
-
#initialize(logger, configuration, subscription_repository) ⇒ EventConsumer
constructor
A new instance of EventConsumer.
- #start ⇒ Object
- #wait_until_connected ⇒ Object
Constructor Details
#initialize(logger, configuration, subscription_repository) ⇒ EventConsumer
Returns a new instance of EventConsumer.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/happn/event_consumer.rb', line 6 def initialize(logger, configuration, subscription_repository) @configuration = configuration @logger = logger @subscription_repository = subscription_repository @queue_name = @configuration.rabbitmq_queue_name = { host: @configuration.rabbitmq_host, port: @configuration.rabbitmq_port&.to_i, user: @configuration.rabbitmq_user, password: @configuration.rabbitmq_password, automatically_recover: true }.merge(@configuration. || {}) @connection = Bunny.new() = { username: @configuration.rabbitmq_user, password: @configuration.rabbitmq_password }.merge(@configuration. || {}) @management_client = RabbitMQ::HTTP::Client.new("#{@configuration.rabbitmq_management_scheme || "http"}://#{@configuration.rabbitmq_host}:#{@configuration.rabbitmq_management_port}/", ) end |
Instance Method Details
#start ⇒ Object
40 41 42 43 |
# File 'lib/happn/event_consumer.rb', line 40 def start wait_until_connected consume end |
#wait_until_connected ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/happn/event_consumer.rb', line 27 def wait_until_connected connected = false while !connected begin connect connected = true rescue Bunny::TCPConnectionFailedForAllHosts @logger.warn("RabbitMQ connection failed, try again in 1 second.") sleep 2 end end end |