Я настраиваю шлюз Zuul.Как я могу избежать Zuul, делающего HTTP-вызовы к конечной точке?Вместо этого я извлек бы значения из кэша, если они доступны, иначе я бы сделал HTTP-вызовы, чтобы получить ответ.
Я бы извлек значения, если они доступны в кэше, иначе я бы сделал HTTP-вызовполучить значения.Реализована эта логика в зуульском фильтре «маршрут».
// This will always make the HTTP request
if(CacheManager.cachedValues.containsKey(key)) {
String body = "hey";
context.setResponseBody(body);
}
@Override
public Object run() {
RequestContext context = RequestContext.getCurrentContext();
HttpServletRequest request = context.getRequest();
String method = request.getMethod();
String uri = request.getRequestURL().toString();
log.info("log from the route filter");
log.info(String.format("%s request to %s", method, uri));
String key = uri.substring(uri.lastIndexOf('/') + 1);
//retrieve values from cache if they are available
if(CacheManager.cachedValues.containsKey(key)) {
String body = "hey";
context.setResponseBody(body);
}else {
//call the http endpoint
}
return null;
}
if(available in the cache ) {
//get the values and return them
} else {
//call the http end point and get the values
//cache the values
}