Git Product home page Git Product logo

kong.net's Introduction

Kong.Net

.NET Core Client of the Kong

How to start

Don't talk anything, 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);
}

kong.net's People

Contributors

lianggx avatar 0xflotus avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.