VOOZH about

URL: https://www.nuget.org/packages/Ocelot.Provider.Nacos/

⇱ NuGet Gallery | Ocelot.Provider.Nacos 1.3.5




Ocelot.Provider.Nacos 1.3.5

dotnet add package Ocelot.Provider.Nacos --version 1.3.5
 
 
NuGet\Install-Package Ocelot.Provider.Nacos -Version 1.3.5
 
 
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Ocelot.Provider.Nacos" Version="1.3.5" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Ocelot.Provider.Nacos" Version="1.3.5" />
 
Directory.Packages.props
<PackageReference Include="Ocelot.Provider.Nacos" />
 
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Ocelot.Provider.Nacos --version 1.3.5
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Ocelot.Provider.Nacos, 1.3.5"
 
 
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Ocelot.Provider.Nacos@1.3.5
 
 
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Ocelot.Provider.Nacos&version=1.3.5
 
Install as a Cake Addin
#tool nuget:?package=Ocelot.Provider.Nacos&version=1.3.5
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Ocelot.Provider.Nacos

Ocelot集成Nacos注册中心组件

开发环境

Nacos 1.x
  • .Net Core 3.1 因为最新稳定版的Ocelot是在.Net Core 3.1上构建的(目前以支持.net5,由张队进行升级的)
  • Ocelot版本 v16.0.1(最新版已是17.0.0)
  • Nacos访问组件 nacos-sdk-csharp
    <PackageReference Include="nacos-sdk-csharp-unofficial" Version="0.2.7" />
    
    它其实是有一个asp.net core版本的组件,但是我没有选用,虽然那个用起来功能很强大,但是我需要自己改造一下,让它能更好的适配Ocelot
Nacos 2.0
 <PackageReference Include="nacos-sdk-csharp" Version="1.3.5" />

添加引用

不同版本支持naocs版本不一样

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

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

<b>目前以支持.net5,请如有需要请引入最新的1.1.0版本</b>

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

dotnet add package Ocelot.Provider.Nacos --version 1.1.0
Nacos 2.0

注意版本1.x和2.x的没做版本兼容,2.x使用以下版本。当时考虑还得在配置文件里做版本区分,所以就独立不同的包了。

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

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

使用方式

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

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

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

{
 "Routes": [
 {
 // 用于服务发现的名称,也就是注册到nacos上的名称
 "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"
}

使用Nacos 2.0的时候注意 nacos-sdk-csharp 1.1.0版本配置文件发生的变化,如果在Nacos 2.0管理界面的服务列表里展示服务,需要新建自己的命名空间并将NameSpace上填写Nacos的NameSpaceId,如下所示

"nacos": {
 "ServerAddresses": [ "http://192.168.219.1:8848" ],
 "ServiceName": "apigateway",
 "DefaultTimeOut": 15000,
 //自定义Namespace的Id,默认的虽然可以注册发现,但是在nacos中不展示
 "Namespace": "2ae308e2-7e8a-4602-9d1c-56508a3e263c",
 "GroupName": "DEFAULT_GROUP",
 "ClusterName": "DEFAULT",
 "ListenInterval": 1000,
 "RegisterEnabled": true,
 "InstanceEnabled": true,
 "LBStrategy": "WeightRandom",
 "NamingUseRpc": true
 }
Product Versions Compatible and additional computed target framework versions.
.NET net6.0 net6.0 is compatible.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 is compatible.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 is compatible.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 was computed.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Ocelot.Provider.Nacos:

Package Downloads
Esun.Common

Package Description

Muzhi.Core

Package Description

Frame.MUZhi.SDK.Core

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.3.5 4,186 1/19/2024
1.3.4 3,244 12/9/2022
1.2.2 6,698 11/25/2021
1.2.0 1,098 7/8/2021
1.2.0-preview.1 461 4/27/2021
1.1.0 1,025 12/14/2020
1.0.0 1,172 7/20/2020