Class: Logbert::Consumers::RedisConsumer

Inherits:
Object
  • Object
show all
Defined in:
lib/logbert/consumers/redis_consumer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(redis_connection, key, options = {}) ⇒ RedisConsumer

Returns a new instance of RedisConsumer.



12
13
14
15
16
# File 'lib/logbert/consumers/redis_consumer.rb', line 12

def initialize(redis_connection, key, options = {})
  @redis    = redis_connection
  @key      = key
  @handlers = options.fetch(:handlers, [])
end

Instance Attribute Details

#handlersObject

Returns the value of attribute handlers.



10
11
12
# File 'lib/logbert/consumers/redis_consumer.rb', line 10

def handlers
  @handlers
end

#keyObject

Returns the value of attribute key.



10
11
12
# File 'lib/logbert/consumers/redis_consumer.rb', line 10

def key
  @key
end

#redisObject

Returns the value of attribute redis.



10
11
12
# File 'lib/logbert/consumers/redis_consumer.rb', line 10

def redis
  @redis
end

Instance Method Details

#workObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/logbert/consumers/redis_consumer.rb', line 18

def work
  # Blocking loop to read serialized messages of the redis queue
  loop do
    msg = redis.brpop(key) # blocking list pop primitive
    @handlers.each do |h|
      m = Message.from_json(msg)
      h.handle_message(m)
    end
  end
end