文章目录
Soul 网关 HTTP 服务探活机制
准备工作
仅启动 soul-admin 与 soul-bootstrap, soul-admin 中有之前测试 Http 转发时注册的服务路径及服务元数据.
在这种情况下, 看看如果没启动相应服务节点的情况会发生什么.
从一个知道会失败的请求开始
尝试调用一个 http路径 http://localhost:9195/http/test/findByUserId?userId=1
, 返回值如下:
{
"code": -106,
"message": "未能找到合适的调用url,请检查你的配置!"
}
继续看看打印的日志信息:
2021-01-20 19:34:42.718 INFO 3929 --- [-work-threads-1] o.d.soul.plugin.base.AbstractSoulPlugin : divide selector success match , selector name :/http
2021-01-20 19:34:42.719 INFO 3929 --- [-work-threads-1] o.d.soul.plugin.base.AbstractSoulPlugin : divide rule success match ,rule name :/http/test/**
2021-01-20 19:34:42.723 ERROR 3929 --- [-work-threads-1] o.d.soul.plugin.divide.DividePlugin : divide upstream configuration error:RuleData(id=1349650853992337408, name=/http/test/**, pluginName=divide, selectorId=1349650852775989248, matchMode=0, sort=1, enabled=true, loged=true, handle={
"requestVolumeThreshold":"0","errorThresholdPercentage":"0","maxConcurrentRequests":"0","sleepWindowInMilliseconds":"0","loadBalance":"roundRobin","timeout":3000,"retry":"0"}, conditionDataList=[ConditionData(paramType=uri, operator=match, paramName=/, paramValue=/http/test/**)])
从日志可以看出 selector 匹配成功, 因为请求的 /http
与选择器中的相同. rule 匹配也成功, 匹配到 /http/test/**
.
最值得注意的是第三行Error级别日志, upstream
相关的错误, 根据日志定位到代码 (仅保留分析代码):
public class DividePlugin extends AbstractSoulPlugin {
protected Mono<Void> doExecute(final ServerWebExchange exchange, final SoulPluginChain chain, final SelectorData selector, final RuleData rule) {
// ...
final List<DivideUpstream> upstreamList = UpstreamCacheManager.getInstance().findUpstreamListBySelectorId(selector.getId());
if (CollectionUtils.isEmpty(upstreamList)) {
LOGGER.error("divide upstream configuration error:{}"