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
- #stop ⇒ Object
- #wait_until_connected ⇒ Object
Constructor Details
#initialize(logger, configuration, subscription_repository) ⇒ EventConsumer
Returns a new instance of EventConsumer.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/happn/event_consumer.rb', line 7 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() @vhost = [:virtual_host] || [:vhost] || "/" = { 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
42 43 44 45 |
# File 'lib/happn/event_consumer.rb', line 42 def start wait_until_connected consume end |
#stop ⇒ Object
47 48 49 50 51 52 |
# File 'lib/happn/event_consumer.rb', line 47 def stop @logger.info("Stopping events consumption...") @consumer&.cancel @consumer = nil @connection.close if @connection.open? end |
#wait_until_connected ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/happn/event_consumer.rb', line 29 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 |