Register your .Net Core web-service in Kong API Gateway on startup and unregister them when you application is shutting down.
Install KongRegister package :
Install-Package KongRegister
Add the following configuration in your appsettings.json :
"KongRegister": {
"KongApiUrl": "http://YourKongApiUrl:8081",
"KongApiKeyHeader": "YourApikeyHeader",
"KongApiKey": "YourApiKey",
"UpstreamId": "YourUpstreamId",
"TargetHostDiscovery": "dynamic",
"TargetHost": "YourTargetHostNameOrIp",
"TargetPortDiscovery": "dynamic",
"TargetPort": 5000,
"TargetWeight": 1000
}
Add the reference in your Startup class :
using KongRegister;
Add those two services in the ConfigureServices method :
public void ConfigureServices(IServiceCollection services)
{
services.Configure<KongRegisterConfig>(Configuration.GetSection("KongRegister"));
services.AddSingleton<IHostedService, KongRegisterService>();
...
}
Run your application, OK it's registered in your Kong server !
Shutdown it, it's now unregistered from Kong !
KongRegister is compatible with:
- Kong CE 0.12.x, 0.13.0
- .Net Core 2.0
- A running Kong installation
- A .Net Core 2.0 web application
You can get help via the issue tracker here on GitHub
- Auto register in Kong server on startup
- Auto unregister from Kong server on shutdown
- Auto discover host IP
- Auto discover host port
You must install KongRegister from NuGet.
Package manager :
Install-Package KongRegister
.Net CLI :
dotnet add package KongRegister
The configuration must be define in the appsettings.json under a root section that you can named it as you choice.
Example :
"KongRegister": {
"KongApiUrl": "http://YourKongApiUrl:8081",
"KongApiKeyHeader": "YourApikeyHeader",
"KongApiKey": "YourApiKey",
"UpstreamId": "YourUpstreamId",
"TargetHostDiscovery": "dynamic",
"TargetHost": "YourTargetHostNameOrIp",
"TargetPortDiscovery": "dynamic",
"TargetPort": 5000,
"TargetWeight": 1000
}
See below all detailed parameters :
Parameter | Type | Description |
---|---|---|
KongApiUrl |
String |
Url of your Kong Admin Api. Don't forget the port if it's not standard (80 or 443) |
KongApiKeyHeader |
String |
Name of your header that contain your API Key (if your Kong server is secured). |
KongApiKey |
String |
Your API Key (if your Kong server is secured). |
UpstreamId |
String |
Kong Upstream Id that you want to register your application into. |
TargetHostDiscovery |
String |
Discovery method for your application host. Value must be dynamic or static |
TargetHost |
String |
Host name or IP of your application host. (if discovery method is static) |
TargetPortDiscovery |
String |
Discovery method for your application host port. Value must be dynamic or static |
TargetPort |
Integer |
Port of your application host (if discovery method is static) |
TargetWeight |
Integer |
Weight for the registered target in Kong server |
Todo
using KongRegister;