
This article will show how to setup API Gateway using Ocelot.Net and Consul.
Step 1
- Set up the Consul Service in Windows, From the below link "https://developer.hashicorp.com/consul/downloads" (Click Here for Download).
- Place in a Directory, open the command prompt, and type the below command to start the development server agent "consul agent -dev".
- Open the Browser and type the following URL "http://127.0.0.1:8500/". If the console UI opens, we set up the Consul properly.
Step 2
In C# Rest Services (Each service needs to be configured like below).
Install Nuget Packages,
- Consul
- Ocelot.Provider.Consul (Gateway Service)
Inject like this in all services (we need to configure service discovery)
services.AddSingleton<IConsulClient, ConsulClient>(p => new ConsulClient(consulConfig =>
{
consulConfig.Address = new Uri("http://127.0.0.1:8500");
}));
Join the conversation! Your thoughts help the community grow.