Configs2026年5月27日·1 分钟阅读

Ocelot — Lightweight API Gateway for .NET

A .NET API gateway that handles routing, authentication, rate limiting, and load balancing for microservice architectures. Configure everything in a single JSON file with no external infrastructure.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Ocelot Overview
直接安装命令
npx -y tokrepo@latest install 28cd00d1-59e9-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

Ocelot is a .NET API gateway designed for microservice architectures. It sits in front of your services and handles cross-cutting concerns like routing, authentication, rate limiting, and load balancing, all configured through a JSON file without requiring external infrastructure like NGINX or Envoy.

What Ocelot Does

  • Routes incoming HTTP requests to downstream services based on URL patterns
  • Supports request aggregation to combine multiple service calls into one response
  • Provides rate limiting and quality-of-service controls per route
  • Integrates with .NET authentication middleware (JWT, OAuth, IdentityServer)
  • Handles load balancing across multiple downstream instances

Architecture Overview

Ocelot runs as ASP.NET Core middleware in a standard .NET web application. It reads route definitions from ocelot.json at startup and builds a pipeline of delegating handlers for each route. Middleware components for authentication, authorization, rate limiting, and caching execute in order for each request before forwarding to the downstream service.

Self-Hosting & Configuration

  • Install the Ocelot NuGet package into an ASP.NET Core project
  • Define routes in ocelot.json with upstream and downstream path templates
  • Register Ocelot in Program.cs: builder.Services.AddOcelot(); app.UseOcelot().Wait();
  • Enable service discovery with Consul or Eureka by adding the corresponding Ocelot package
  • Configure caching with Ocelot.Cache.CacheManager for response caching

Key Features

  • JSON-based configuration with no external gateway infrastructure needed
  • Built-in support for Consul and Eureka service discovery
  • Request aggregation reduces chattiness between client and microservices
  • Middleware pipeline integrates with standard ASP.NET Core auth and logging
  • Supports WebSocket proxying and header transformation

Comparison with Similar Tools

  • YARP — Microsoft's reverse proxy library; lower-level and more flexible but requires more code
  • Kong — full-featured gateway with plugins; Ocelot is lighter and .NET-native
  • Envoy — high-performance C++ proxy; Ocelot is simpler for .NET teams who want in-process control
  • Traefik — auto-discovers services via Docker labels; Ocelot uses JSON config or service registries
  • Azure API Management — managed cloud service; Ocelot is self-hosted and free

FAQ

Q: Is Ocelot suitable for production use? A: Yes. Ocelot is used in production .NET microservice deployments and supports horizontal scaling behind a load balancer.

Q: Can Ocelot handle authentication? A: Yes. It integrates with ASP.NET Core authentication middleware, supporting JWT bearer tokens, OAuth 2.0, and IdentityServer.

Q: Does Ocelot support gRPC? A: Ocelot primarily handles HTTP traffic. For gRPC, teams typically use Envoy or YARP as the proxy layer.

Q: How do I update routes without restarting? A: Ocelot supports dynamic configuration reloading and integration with Consul for real-time route updates.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产