Skip to content
javasoze edited this page Dec 30, 2012 · 1 revision

Given a partition, there may be N replicas that can serve data, e.g.

partitionId -> list of nodes (InetSocketAddress) instances

Routing: to choose a node to serve the request.

Zu defines an API for routing: RoutingAlgorithm, and provides a few implementations:

  • Random - random chooses one node in the list, each node has equal chance to be chosen.
  • RoundRobin - cycles thru the list and chooses the next node in the list.
  • ConsistentHash - hash into the list, and given a key, the same node is returned.

Implementations of RoutingAlgorithm also implement ZuClusterEventListener. So just register to a cluster and call route to get a node to server:

// setup

ZuCluster cluster = ...

RoutingAlgorithm router = new ConsistentHashRoutingAlgorithm();

cluster.addClusterEventListener(router);

// for a given request, for partition 1

byte[] requestKey = ...

InetSocketAddress node = router.route(requestKey, 1);

Clone this wiki locally