Repo for Nacos integration with Ocelot
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Go to file
Mr Li 05130b9e4a
Update README.md
5 years ago
demo 修改发布信息 5 years ago
src/Ocelot.Provider.Nacos 修改发布信息 5 years ago
test/Ocelot.Provider.Nacos.Test 修改项目结构 5 years ago
.gitignore 完成代码编写 5 years ago
Ocelot.Provider.Nacos.sln 修改项目结构 5 years ago
README.md Update README.md 5 years ago

README.md

Ocelot.Provider.Nacos

Ocelot集成Nacos注册中心组件

开发环境

  • .Net Core 3.1 因为最新稳定版的Ocelot是在.Net Core 3.1上构建的
  • Ocelot版本 v16.0.1
  • Nacos访问组件 nacos-sdk-csharp-unofficial v0.2.7

添加引用

<PackageReference Include="Ocelot.Provider.Nacos" Version="1.0.0" />

dotnet add package Ocelot.Provider.Nacos --version 1.0.0

使用方式

在已有的Ocelot的项目上添加以下内容具体操作可查看demo

public void ConfigureServices(IServiceCollection services)
{
    //注册服务发现
    services.AddOcelot().AddNacosDiscovery();
}

再已有的ocelot配置文件上添加

{
  "Routes": [
    {
      "ServiceName": "productservice",
      "DownstreamScheme": "http",
      "DownstreamPathTemplate": "/productapi/{everything}",
      "UpstreamPathTemplate": "/productapi/{everything}",
      "UpstreamHttpMethod": [ "Get", "Post" ],
      "LoadBalancerOptions": {
        "Type": "RoundRobin"  
      },
      // 使用服务发现
      "UseServiceDiscovery": true
    }
  ],
  "GlobalConfiguration": {
    "ServiceDiscoveryProvider": {
      //这里是重点
      "Type": "Nacos"
    }
  }
}

然后添加在appsettings.json文件中添加,具体配置字段和nacos-sdk-csharp是保持一致的

"nacos": {
    "ServerAddresses": [ "http://localhost:8848" ],
    "DefaultTimeOut": 15000,
    "Namespace": "",
    "ListenInterval": 1000,
    "ServiceName": "apigateway"
}