Skip to content

Sample implementation of microservice with MongoDB database, Ocelot API gateway and a simple Redis Caching at the reporting service

Notifications You must be signed in to change notification settings

osemeke/dotnet6-MongoDB-Microservices

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

dotnet6-MongoDB-Microservices

Sample implementation of microservice with MongoDB database, Ocelot API gateway and a simple Redis Caching at the reporting service

Ocelot API Gateway Implementation

  • Empty project or minimal API
  • Install-Package Ocelot
  • add ocelot.json configuration
  • add Logging
  • Ensure CORS is enabled on the services
  • Ensure there is no 403 redirects to https when testing on http

Sample .net6 minimal API code

using Ocelot.DependencyInjection;
using Ocelot.Middleware;
using Ocelot.Cache.CacheManager;

var builder = WebApplication.CreateBuilder(args);

builder.Configuration.AddJsonFile($"ocelot.{builder.Environment.EnvironmentName}.json", true, true);

builder.Logging.AddConfiguration(builder.Configuration.GetSection("Logging"));
builder.Logging.AddConsole();
builder.Logging.AddDebug();

builder.Services.AddOcelot();

var app = builder.Build();

app.UseRouting();

app.UseEndpoints(endpoints =>
{
    endpoints.MapGet("/", async context =>
    {
        await context.Response.WriteAsync("API Gateway!");
    });
});

await app.UseOcelot(); 

app.Run();

About

Sample implementation of microservice with MongoDB database, Ocelot API gateway and a simple Redis Caching at the reporting service

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages