Qianshi's Blog
106 字
1 分钟
ocelot 新版本获取下游服务地址变更
2024-09-20

错误原因:Ocelot 新版本在 Consul 获取服务地址时默认返回的是节点名称 node != null ? node.Name : entry.Service.Address

解决方案:继承默认的 DefaultConsulServiceBuilder,重写 GetDownstreamHost方法。

Service Discovery — Ocelot 23.3 documentation

After Upgrade to 23.3.3 from 23.2.2 cluster name is being used in place of service address · Issue #2109 · ThreeMammals/Ocelot (github.com)

public class ConsulServiceBuilder : DefaultConsulServiceBuilder
{
    public ConsulServiceBuilder(Func<ConsulRegistryConfiguration> configurationFactory, IConsulClientFactory clientFactory, IOcelotLoggerFactory loggerFactory) : base(configurationFactory, clientFactory, loggerFactory)
    {
    }

    protected override string GetDownstreamHost(ServiceEntry entry, Node node)
    {
        return entry.Service.Address;
    }
}

ocelot 新版本获取下游服务地址变更
https://kuriyama.top/posts/gateway/ocelot-new-version-get-downstream-host-change/
作者
Qian Shi
发布于
2024-09-20
许可协议
CC BY-NC-SA 4.0