Cluster Subscriptions with Topology Changes #1811
-
I'd like to subscribe to key-space notifications using Redis Pub/Sub on a cluster. What do I need to do to ensure that new nodes being added to the Redis cluster are also subscribed to? According to the documentation, this can be a bit of a gotcha because:
Since key-space notifications are node-local, I have this sort of setup: RedisClusterClient clusterClient = RedisClusterClient.create("someuri");
clusterClient.setOptions(ClusterClientOptions.builder()
.topologyRefreshOptions(ClusterTopologyRefreshOptions.builder()
.enableAllAdaptiveRefreshTriggers()
.enablePeriodicRefresh()
.build())
.build());
StatefulRedisClusterPubSubConnection<String, String> pubSubConnection = clusterClient.connectPubSub();
pubSubConnection.setNodeMessagePropagation(true); Is there some kind of Topology hook that I can tap into so that the new nodes get the subscription (and Lettuce listens to them)? Is there something I need to do with the NodeSelection API? And secondarily, what's a good way to ensure that you only subscribe to the master cluster nodes (while again keeping up with topology changes) to avoid duplication issues?
If it was just |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Cluster Keyspace Notifications are hard to do right because a cluster changes its topology without a reliable source for change notifications. The only mechanism is polling for changes.
Lettuce emits
You can either subscribe through the NodeSelection API or track nodes yourself by inspecting Note that |
Beta Was this translation helpful? Give feedback.
Cluster Keyspace Notifications are hard to do right because a cluster changes its topology without a reliable source for change notifications. The only mechanism is polling for changes.
Lettuce emits
ClusterTopologyChangedEvent
through its event bus. You can subscribe toClientResources.eventBus().get()
to listen for these events.You can either subscribe through the NodeSelection API or track nodes yourself by inspecting
Partitions
.Note that
ReadFrom
helps to route commands to replicas/master nodes, however keyspace notifications are active push messag…