| Class | Beetle::RedisConfigurationClient |
| In: |
lib/beetle/redis_configuration_client.rb
|
| Parent: | Object |
A RedisConfigurationClient is the subordinate part of beetle‘s redis failover solution
An instance of RedisConfigurationClient lives on every server that hosts message consumers (worker server).
It is responsible for determining an initial redis master and reacting to redis master switches initiated by the RedisConfigurationServer.
It will write the current redis master host:port string to a file specified via a Configuration, which is then read by DeduplicationStore on redis access.
Usually started via beetle configuration_client command.
| current_master | [R] | The current redis master |
| id | [W] | Set a custom unique id for this instance. Must match an entry in Configuration#redis_configuration_client_ids. |
Beetle::Client instance for communication with the RedisConfigurationServer
# File lib/beetle/redis_configuration_client.rb, line 74
74: def beetle
75: @beetle ||= build_beetle
76: end
called by the message dispatcher when a "invalidate" message from RedisConfigurationServer is received
# File lib/beetle/redis_configuration_client.rb, line 55
55: def invalidate(payload)
56: token = payload["token"]
57: logger.info "Received invalidate message with token '#{token}'"
58: invalidate! if redeem_token(token) && !current_master.try(:master?)
59: end
called by the message dispatcher when a "pong" message from RedisConfigurationServer is received
# File lib/beetle/redis_configuration_client.rb, line 48
48: def ping(payload)
49: token = payload["token"]
50: logger.info "Received ping message with token '#{token}'"
51: pong! if redeem_token(token)
52: end
called by the message dispatcher when a "reconfigure"" message from RedisConfigurationServer is received
# File lib/beetle/redis_configuration_client.rb, line 62
62: def reconfigure(payload)
63: server = payload["server"]
64: token = payload["token"]
65: logger.info "Received reconfigure message with server '#{server}' and token '#{token}'"
66: return unless redeem_token(token)
67: unless server == read_redis_master_file
68: new_master!(server)
69: write_redis_master_file(server)
70: end
71: end
determinines the initial redis master (if possible), then enters a messaging event loop, reacting to failover related messages sent by RedisConfigurationServer.
# File lib/beetle/redis_configuration_client.rb, line 38
38: def start
39: verify_redis_master_file_string
40: logger.info "RedisConfigurationClient starting (client id: #{id})"
41: determine_initial_master
42: clear_redis_master_file unless current_master.try(:master?)
43: logger.info "Listening"
44: beetle.listen
45: end