Ocelot 配置初始
{
"ReRoutes": [
{
/*将用户的请求 /post/1 转发到 localhost/api/post/1*/
/*
DownstreamPathTemplate:转到的地址
DownstreamScheme:转到的请求协议
DownstreamHostAndPorts:转到的端口地址及端口信息
UpstreamPathTemplate:监听路由地址
UpstreamHttpMethod:监听路由请求类型 可用数组
Priority:路由的优先级Prority是大的会被优先选择
万能模版转发:
{
"DownstreamPathTemplate": "/{url}",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 80,
}
],
"UpstreamPathTemplate": "/{url}",
"UpstreamHttpMethod": [ "Get" ]
}
*/
"DownstreamPathTemplate": "/api/post/{postId}",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port":
}
],
"UpstreamPathTemplate": "/post/{postId}",
"UpstreamHttpMethod": [ "Get" ],
"Priority": ,
/*设置HttpHeaders*/
"AddHeadersToRequest": {},
"AddClaimsToRequest": {},
/*
鉴权
我们通过认证中的AllowedScopes 拿到claims之后,如果要进行权限的鉴别需要添加以下配置
"RouteClaimsRequirement": {
"UserType": "registered"
}
*/
"RouteClaimsRequirement": {},
"AddQueriesToRequest": {},
"RequestIdKey": "",
/*
缓存
Ocelot可以对下游请求结果进行缓存 ,目前缓存的功能还不是很强大。它主要是依赖于CacheManager 来实现的,我们只需要在路由下添加以下配置即可
Region是对缓存进行的一个分区,我们可以调用Ocelot的 administration API来移除某个区下面的缓存
*/
"FileCacheOptions": {
"TtlSeconds": ,
"Region": "somename"
},
"ReRouteIsCaseSensitive": false,
"ServiceName": "",
/*
服务质量与熔断:熔断的意思是停止将请求转发到下游服务。当下游服务已经出现故障的时候再请求也是功而返,并且增加下游服务器和API网关的负担。这个功能是用的Pollly来实现的,我们只需要为路由做一些简单配置即可
ExceptionsAllowedBeforeBreaking 允许多少个异常请求
DurationOfBreak 熔断的时间,单位为秒
TimeoutValue 如果下游请求的处理时间超过多少则自如将请求设置为超时
*/
"QoSOptions": {
"ExceptionsAllowedBeforeBreaking": ,
"DurationOfBreak": ,
"TimeoutValue":
},
/*
LeastConnection – 将请求发往最空闲的那个服务器
RoundRobin – 轮流发送
NoLoadBalance – 总是发往第一个请求或者是服务发现
*/
"LoadBalancer": "", //将决定负载均衡的算法
/*
限流
对请求进行限流可以防止下游服务器因为访问过载而崩溃,
非常优雅的实现,我们只需要在路由下加一些简单的配置即可以完成
ClientWihteList 白名单
EnableRateLimiting 是否启用限流
Period 统计时间段:1s, 5m, 1h, 1d
PeroidTimeSpan 多少秒之后客户端可以重试
Limit 在统计时间段内允许的最大请求数量
*/
"RateLimitOptions": {
"ClientWhitelist": [],
"EnableRateLimiting": false,
"Period": "",
"PeriodTimespan": ,
"Limit":
},
/*
认证
如果我们需要对下游API进行认证以及鉴权服务的,则首先Ocelot 网关这里需要添加认证服务。这和我们给一个单独的API或者ASP.NET Core Mvc添加认证服务没有什么区别。
JWT Token
public void ConfigureServices(IServiceCollection services)
{
var authenticationProviderKey = "ProviderKey";
services.AddAuthentication()
.AddJwtBearer(authenticationProviderKey, x =>
{
});
}
然后在ReRoutes的路由模板中的AuthenticationOptions进行配置,只需要我们的AuthenticationProviderKey一致即可。
"AuthenticationOptions": {
"AuthenticationProviderKey": "ProviderKey",
"AllowedScopes": []
}
}]
添加Identity Server的认证也是一样
public void ConfigureServices(IServiceCollection services)
{
var authenticationProviderKey = "TestKey";
var options = o =>
{
o.Authority = "identityserver4的地址";
o.ApiName = "api";
o.SupportedTokens = SupportedTokens.Both;
o.ApiSecret = "secret";
};
services.AddAuthentication()
.AddIdentityServerAuthentication(authenticationProviderKey, options);
services.AddOcelot();
}
*/
"AuthenticationOptions": {
"AuthenticationProviderKey": "",
"AllowedScopes": []
},
/*
*/
"HttpHandlerOptions": {
"AllowAutoRedirect": true,
"UseCookieContainer": true,
"UseTracing": true
},
"UseServiceDiscovery": false,
"Key": "keys1"
}
],
"Aggregates": [
{
"ReRouteKeys": [
"keys1",
"keys2"
],
"UpstreamPathTemplate": "/"
}
],
"GlobalConfiguration": {
"BaseUrl": "http://localhost:5002"
}
}
Ocelot 配置初始的更多相关文章
- 写个重新加载 ocelot 配置的接口
写个重新加载 ocelot 配置的接口 Intro 我们想把 ocelot 的配置放在自己的存储中,放在 Redis 或者数据库中,当修改了 Ocelot 的配置之后希望即时生效,又不想在网关这边定时 ...
- .Net微服务实践(三):Ocelot配置路由和请求聚合
目录 配置 路由 基本配置 占位符 万能模板 优先级 查询参数 请求聚合 默认聚合 自定义聚合 最后 在上篇.Net微服务实践(二):Ocelot介绍和快速开始中我们介绍了Ocelot,创建了一个Oc ...
- CentOs安装Mysql和配置初始密码
mysql官网yum安装教程,地址:https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/#repo-qg-yum-fresh-install ...
- 微服务网关从零搭建——(六)ocelot配置追踪功能
butterfly 准备工作 首先下载buterfly release版本 解压并通过命令启动:dotnet Butterfly.Web.dll --EnableHttpCollector=true ...
- Ocelot 配置参数
Downstream是下游服务配置 UpStream是上游服务配置 Aggregates 服务聚合配置 ServiceName, LoadBalancer, UseServiceDiscovery 配 ...
- .net5+nacos+ocelot 配置中心和服务发现实现
最近一段时间 因公司业务需要,需要使用.net5做一套微服务的接口,使用nacos 做注册中心和配置中心,ocelot做网关. 因为ocelot 支持的是consol和eureka,如果使用nacos ...
- ocelot配置
动态配置 { "ReRoutes": [], "Aggregates": [], "GlobalConfiguration": { &quo ...
- hbuider配置初始
{ "forEach": { "prefix": "fec", "body": [ ".forEach(fun ...
- Hadoop 管理工具HUE配置-初始配置
1 界面换成中文 默认是英文的,可以修改为中文 1.修改配置文件settings.pynano hue/desktop/core/src/desktop/settings.py LANGUAGE_CO ...
随机推荐
- linux 中 virtualenvwrapper的使用
原文链接:http://www.jianshu.com/p/3abe52adfa2b Virtaulenvwrapper Virtaulenvwrapper是virtualenv的扩展包,用于更方便管 ...
- JS获取FckEditor的值
不需要在页面引用任何额外的JS文件 //获取编辑器中HTML内容 function getEditorHTMLContents(EditorName) { var oEditor = FCKedito ...
- IOS的__bridge
使用 __bridge 关键字来实现id类型与void*类型的相互转换.看下面的例子. id obj = [[NSObject alloc] init]; void *p = (__bridge vo ...
- 悬浮按钮css
.floating-button { color: #fff; position: absolute; right: 16px; bottom: 88px; width: 56px; height: ...
- 2. Jmeter压力测试简单教程(包括服务器状态监控) (转)
转自:https://blog.csdn.net/cbzcbzcbzcbz/article/details/78023327 前段时间公司需要对服务器进行压力测试,包括登录前的页面和登录后的页面,主要 ...
- negativeView 的使用
参考链接:http://blog.csdn.net/u012702547/article/details/51253222 1.一般来讲,是配合drawerLayout使用的,在xml文件中声明,其中 ...
- myapplication 单例写法
MyApplication extends Application private static MyApplication myApplication = null; oncreate中: @Ove ...
- Spring IOC 容器
<bean name="userBean" class="com.nuts.demo.spring.UserBean"> <property ...
- bzoj 2342 [Shoi2011]双倍回文(manacher,set)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2342 [题意] 求出形如w wR w wR的最长连续子串. [思路] 用manache ...
- 基本控件文档-UIView属性
CHENYILONG Blog 基本控件文档-UIView属性 Fullscreen UIView属性技术博客http://www.cnblogs.com/ChenYilong/ 新浪微博http ...