Listen for new messages via keyspace notifications.

This commit is contained in:
Jon Chambers
2020-08-06 11:21:55 -04:00
committed by Jon Chambers
parent 2c29f831e8
commit 8d3316ccd6
10 changed files with 313 additions and 21 deletions

View File

@@ -17,6 +17,7 @@ import org.slf4j.LoggerFactory;
import org.whispersystems.textsecuregcm.redis.ClusterLuaScript;
import org.whispersystems.textsecuregcm.redis.FaultTolerantRedisCluster;
import org.whispersystems.textsecuregcm.util.Constants;
import org.whispersystems.textsecuregcm.util.RedisClusterUtil;
import java.io.IOException;
import java.time.Duration;
@@ -81,15 +82,9 @@ public class ClientPresenceManager extends RedisClusterPubSubAdapter<String, Str
@Override
public void start() {
RedisClusterUtil.assertKeyspaceNotificationsConfigured(presenceCluster, "K$");
presenceCluster.usePubSubConnection(connection -> {
final String configuredKeyspaceNotifications = connection.sync().configGet("notify-keyspace-events").getOrDefault("notify-keyspace-events", "");
for (final char requiredNotificationType : new char[] {'K', '$'}) {
if (configuredKeyspaceNotifications.indexOf(requiredNotificationType) == -1) {
throw new IllegalStateException("Required keyspace notification type not configured. Need at least K$, but is actually: " + configuredKeyspaceNotifications);
}
}
connection.addListener(this);
connection.getResources().eventBus().get()
.filter(event -> event instanceof ClusterTopologyChangedEvent)