SOURCE

function random(serviceId) {
  // random flow   
  // ...   
  return 'xxx.xxx.xxx.xxx';
}
function weightedRoundRobin(serviceId) {
  // weightedRoundRobin flow   
  // ...   
  return 'xxx.xxx.xxx.xxx';
}
function ipHash(serviceId) {
  // IPHash flow   
  // ...   
  return 'xxx.xxx.xxx.xxx';
}
function urlHash(serviceId) {
  // URL Hash flow   
  // ...   
  return 'xxx.xxx.xxx.xxx';
}
function leastConnection(serviceId) {
  // leaseConnection flow   
  // ...   
  return 'xxx.xxx.xxx.xxx';
}
function fair(serviceId) {
  // fair flow   
  // ...   
  return 'xxx.xxx.xxx.xxx';
}

const ALGORITHM = {
  RANDOM: 'random',
  WEIGHTED_ROUND_ROBIN: 'weightedRoundRobin',
  IP_HASH: 'ipHash',
  URL_HASH: 'urlHash',
  LEAST_CONNECTION: 'leastConnection',
  FAIR: 'fair',
};

const ALGORITHM_MAP = {
  [ALGORITHM.RANDOM]: random,
  [ALGORITHM.WEIGHTED_ROUND_ROBIN]: weightedRoundRobin,
  [ALGORITHM.IP_HASH]: ipHash,
  [ALGORITHM.URL_HASH]: urlHash,
  [ALGORITHM.LEAST_CONNECTION]: leastConnection,
  [ALGORITHM.FAIR]: fair,
};

function consul(serviceId, algorithm) {
  return ALGORITHM_MAP[algorithm](serviceId);
}
console 命令行工具 X clear

                    
>
console