Pattern
Client Side Discovery
- ttnet?
Server Side Discovery
Methods
- DNS SRV records
- Downside
- Rely on cache
- No health check
- No notification mechanism
- Downside
- mDNS (multicase DNS)
- Downside
- Rely on cache
- Rely on IP multicast
- No health check
- No notification mechanism
- Downside
- ZooKeeper / Apache Curator
Example
const response = await fetch("http://inventory/stock/apple");
if (!response.ok) {
throw new Error(`库存查询失败:${response.status}`);
}
const stock = await response.json();
console.log(stock.remaining);