Skip to content
.NET Core Client of the Kong
Branch: master
Clone or download
Latest commit 6a66740 Jul 10, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples/Kong.Example 0.0.5 Jul 10, 2019
src 0.0.5 Jul 10, 2019
test/Kong.XUnitTest Construction projects Jul 6, 2019
.gitignore readme Jul 6, 2019
Kong.Net.sln readme Jul 6, 2019
Kong.sln Construction projects Jul 6, 2019
LICENSE Initial commit Jul 6, 2019
README.md Update README.md Jul 10, 2019

README.md

Kong.Net

.NET Core Client of the Kong

How to start

Don't talk anying,Just do it!(±ð˵»°£¬¾ÍÊǸɣ¡)

Using Kong.Net

Install-Package Kong.Net -Version 0.0.4
Install-Package Kong.Extensions -Version 0.0.4

Add JSON section to appsettings.json

"kong": {
    "host": "http://10.23.11.1:8001",
    "upstream": {
      "tags": [ "example", "low-priority" ],
      "name": "Kong.Example",
      "hash_on": "none",
      "healthchecks": {
        "active": {
          "unhealthy": {
            "http_statuses": [ 429, 500, 501, 502, 503, 504, 505 ],
            "tcp_failures": 1,
            "timeouts": 1,
            "http_failures": 1,
            "interval": 5
          },
          "type": "http",
          "http_path": "/kong/healthchecks",
          "timeout": 1,
          "healthy": {
            "successes": 1,
            "interval": 5,
            "http_statuses": [ 200, 302 ]
          },
          "https_verify_certificate": true,
          "concurrency": 1
        },
        "passive": {
          "unhealthy": {
            "http_statuses": [ 429, 500, 501, 502, 503, 504, 505 ]
          },
          "healthy": {
            "http_statuses": [ 200, 302 ]
          },
          "type": "http"
        }
      },
      "hash_on_cookie_path": "/",
      "hash_fallback": "none",
      "slots": 10000
    },
    "target": {
      "tags": [ "example", "low-priority" ],
      "target": "192.168.1.10:5200",
      "weight": 100
    }
  }

The JSON section kong.target.target Is Kong.Net Service Registration , The sexion value required!

KongClient Injection To Service container

		// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
    services.AddSingleton<KongClient>(fat =>
    {
        var options = new KongClientOptions(HttpClientFactory.Create(), this.Configuration["kong:host"]);
        var client = new KongClient(options);
        return client;
    });
}

Configure Kong Client to Startup

public void Configure(IApplicationBuilder app, IHostingEnvironment env, KongClient kongClient)
{
    app.UseKong(Configuration, kongClient);

    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }

    app.UseMvc();
}

Custom Kong Client Host:Port

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, KongClient kongClient)
{
    UseKong(app, kongClient);

    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }

    app.UseMvc();
}

public void UseKong(IApplicationBuilder app, KongClient kongClient)
{
    var upStream = Configuration.GetSection("kong:upstream").Get<UpStream>();
    var target = Configuration.GetSection("kong:target").Get<TargetInfo>();
    var uri = new Uri(Configuration["server.urls"]);
	// This target is your host:port
    target.Target = uri.Authority;
    app.UseKong(kongClient, upStream, target);
}

Custom HealthChecks

public void UseKong(IApplicationBuilder app, KongClient kongClient)
{
    var upStream = Configuration.GetSection("kong:upstream").Get<UpStream>();
    var target = Configuration.GetSection("kong:target").Get<TargetInfo>();
    var uri = new Uri(Configuration["server.urls"]);
    target.Target = uri.Authority;

	// Set parameter onExecuter to Custom HealthChecks
    app.UseKong(kongClient, upStream, target, OnExecuter);
}

/// <summary>
/// Custom HealthChecks
/// </summary>
/// <param name="context"></param>
public void OnExecuter(HttpContext context)
{
    context.Response.StatusCode = 500;
}
You can’t perform that action at this time.