SmartIot.Consul.Core 1.0.0

dotnet add package SmartIot.Consul.Core --version 1.0.0
NuGet\Install-Package SmartIot.Consul.Core -Version 1.0.0
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="SmartIot.Consul.Core" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SmartIot.Consul.Core --version 1.0.0
#r "nuget: SmartIot.Consul.Core, 1.0.0"
#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.
// Install SmartIot.Consul.Core as a Cake Addin
#addin nuget:?package=SmartIot.Consul.Core&version=1.0.0

// Install SmartIot.Consul.Core as a Cake Tool
#tool nuget:?package=SmartIot.Consul.Core&version=1.0.0

SmartIot.Consul

SmartIot.Consul 是安徽斯玛特公司根据公司自用的实际情况进行简单封装。

使用方法

aspnetcore项目nuget添加Consul引用

对本库添加引用

  • git add submodule
  • 添加引用SmartIot.Consul.Core项目

配置

  • config目录中的consul.json文件即配置文件,内容如下所示:
{
  "ServiceDiscovery": {
    "ServiceName": "ServiceC",
    "Consul": {
      "HttpEndpoint": "http://localhost:8500"
    }
  }
}

ServiceName是注册到Consul的Service Name
HttpEndpoint 是Consul服务的地址

Startup文件

public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddConsul();

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseMvc();


            app.UseConsul();
        }
    }

注意点:

可在自己项目的根目录中添加config目录,在config目录中添加consul.json文件,并设置为生成输出,可覆盖SmartIot.Consul.Core中的配置文件。

示例代码

ServiceA 和 ServiceB两个项目为原始使用consul的方式 ServiceC 项目为使用SmartIot.Consul.Core的方式 SmartIotOcelot 项目为 Ocelot + Consul 的测试项目

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 554 6/3/2019