使用ocelot作为api网关
- 新建网站项目然后添加ocelot 的nuget包
- 新建ocelot.json的网关的配置文件
{
"GlobalConfiguration": {
"BaseUrl": "https://api.mybusiness.com"
},
"ReRoutes": [
{
"DownstreamPathTemplate": "/api/values",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port":
}
],
"UpstreamPathTemplate": "/users",
"UpstreamHttpMethod": [ "Get" ],
"AuthenticationOptions": {
"AuthenticationProviderKey": "finbook",
"AllowedScopes": []
}
},
{
"DownstreamPathTemplate": "/connect/token",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port":
}
],
"UpstreamPathTemplate": "/connect/token",
"UpstreamHttpMethod": [ "Post" ]
}
]
} - 添加配置文件进入netcore管道
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
} public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext, builder) =>
{
builder
.SetBasePath(hostingContext.HostingEnvironment.ContentRootPath)
.AddJsonFile("Ocelot.json");
})
.UseStartup<Startup>()
.Build();
}public void ConfigureServices(IServiceCollection services)
{
services.AddOcelot();
} - 集成identityserver
services.AddAuthentication()
.AddIdentityServerAuthentication(authenticationProviderKey, options=> {
options.Authority = "http://localhost:52619/";
options.ApiName = "geteway_api";
options.SupportedTokens = SupportedTokens.Both;
options.ApiSecret = "secret";
options.RequireHttpsMetadata = false;//是否是https请求
}); - 参考自大佬文章http://www.jessetalk.cn/2018/03/19/net-core-apigateway-ocelot-docs/
使用ocelot作为api网关的更多相关文章
- Ocelot实现API网关服务
NET Core微服务之基于Ocelot实现API网关服务 https://www.cnblogs.com/edisonchou/p/api_gateway_ocelot_foundation_01. ...
- .NET Core微服务之基于Ocelot实现API网关服务
Tip: 此篇已加入.NET Core微服务基础系列文章索引 一.啥是API网关? API 网关一般放到微服务的最前端,并且要让API 网关变成由应用所发起的每个请求的入口.这样就可以明显的简化客户端 ...
- .NET Core微服务之基于Ocelot实现API网关服务(续)
Tip: 此篇已加入.NET Core微服务基础系列文章索引 一.负载均衡与请求缓存 1.1 负载均衡 为了验证负载均衡,这里我们配置了两个Consul Client节点,其中ClientServic ...
- NET Core微服务之路:基于Ocelot的API网关Relay实现--RPC篇
前言 我们都知道,API网关是工作在应用层上网关程序,为何要这样设计呢,而不是将网关程序直接工作在传输层.或者网络层等等更底层的环境呢?让我们先来简单的了解一下TCP/IP的五层模型. (图片 ...
- .net core Ocelot实现API网关并部署在docker中
基于Ocelot(http://ocelot.readthedocs.io)搭建的API网关demo 软件以及系统版本: Asp.Net Core 2.2 Ocelot 13.5.0 CentOS ...
- .net core Ocelot Consul 实现API网关 服务注册 服务发现 负载均衡
大神张善友 分享过一篇 <.NET Core 在腾讯财付通的企业级应用开发实践>里面就是用.net core 和 Ocelot搭建的可扩展的高性能Api网关. Ocelot(http:// ...
- ASP.NET Core on K8S学习之旅(13)Ocelot API网关接入
本篇已加入<.NET Core on K8S学习实践系列文章索引>,可以点击查看更多容器化技术相关系列文章. 上一篇介绍了Ingress的基本概念和Nginx Ingress的基本配置和使 ...
- Angular SPA基于Ocelot API网关与IdentityServer4的身份认证与授权(一)
好吧,这个题目我也想了很久,不知道如何用最简单的几个字来概括这篇文章,原本打算取名<Angular单页面应用基于Ocelot API网关与IdentityServer4+ASP.NET Iden ...
- Angular SPA基于Ocelot API网关与IdentityServer4的身份认证与授权(二)
上文已经介绍了Identity Service的实现过程.今天我们继续,实现一个简单的Weather API和一个基于Ocelot的API网关. 回顾 <Angular SPA基于Ocelot ...
随机推荐
- JavaWeb--ServletContext
https://www.jianshu.com/p/31d27181d542 java类中获取ServletContext的方法 起因是我想要获取一个相对路径,需要用到servletContext的g ...
- jQuery attr() prop() data()用法及区别
.attr(),此方法从jq1.0开始一直存在,官方文档写的作用是读/写DOM的attribute值,其实1.6之前有时候是attribute,有时候又是property..prop(),此方法jq1 ...
- 【JZOJ5180】【NOI2017模拟6.29】呵呵
题目 分析 套上prufer序列, 对于一颗n个节点度数分别为\(d_1.d_2...d_n\)方案数为\(\dfrac{(n-2)!}{(d_1-1)!(d_2-1)!......(d_n-1)!} ...
- 基于Python原生asyncio模块对DNS正向和反向的解析
一.正向解析:域名解析IP地址 import asyncio import socket domains = [ ('www.baidu.com', 'https'), ('cn.bing.com', ...
- CSS之咖啡菜单网页设计
今天记录学习的设计网站首页的咖啡菜单,综合运用所学习的html,css背景,文本,字体,链接,表格,盒子,选择器,定位,以及css3的阴影,圆角边框,2d变换等内容. ㈠咖啡菜单整体样式 运用html ...
- 【UOJ#129】 【NOI2015】寿司晚宴
题目描述 为了庆祝 NOI 的成功开幕,主办方为大家准备了一场寿司晚宴.小 G 和小 W 作为参加 NOI 的选手,也被邀请参加了寿司晚宴. 在晚宴上,主办方为大家提供了 n−1 种不同的寿司,编号 ...
- hdu_1712(dp,背包)
hdu_1712 \[dp[i][j]\] 表示前i个物品用了j天得到的最大收益 \[ dp[i][j] = max(dp[i-1][j],dp[i][j-k]+ k*v[i][k]) \qquad ...
- C++入门经典-例6.12-使用数组地址将二维数组输出
1:以a[4][3]为例 a代表二维数组的地址,通过指针运算符可以获取数组中的元素 (1)a+n代表第n行的首地址 (2)&a[0][0]既可以看作第0行0列的首地址,同样也可以被看作是二维数 ...
- LeetCode 98. 验证二叉搜索树(Validate Binary Search Tree)
题目描述 给定一个二叉树,判断其是否是一个有效的二叉搜索树. 假设一个二叉搜索树具有如下特征: 节点的左子树只包含小于当前节点的数. 节点的右子树只包含大于当前节点的数. 所有左子树和右子树自身必须也 ...
- 使用C#语言,将DataTable 转换成域模型
DataTable dt = SqlHelper.Query(strQuery); ) * size).Take(pagesize); List<Model> listData = new ...