Ocelot 新手上路
新手上路,老司机请多多包含!Ocelot 在博园里文章特别多,但是按照其中一篇文章教程,如果经验很少或者小白,是没法将程序跑向博主的结果.
因此总结下 参考多篇文章,终于达到预期效果。
Ocelot 目标是使用.NET运行微服务/面向服务架构,我们需要一个统一的入口进入我们的服务,提供监控、鉴权、负载均衡等机制,也可以通过编写中间件的形式,来扩展Ocelot的功能。 Ocelot是一堆特定顺序的中间件。
Ocelot开源地址:https://github.com/TomPallister/Ocelot

分别创建三个API
1.ApiGateway
2.WebApiA
3.WebApiB

以 APIGateway 项目 Nuget控制台,执行Ocelot安装。
PM>Install-Package Ocelot 按回车等待安装

如果看到这种情况 恭喜你 环境基本就绪 咱们开始走上编码

1、APIGateway修改Startup
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddOcelot(new ConfigurationBuilder()
.AddJsonFile("configuration.json")
.Build());
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public async void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
await app.UseOcelot();
app.UseMvc();
}
}
添加命名空间
using Ocelot.DependencyInjection;
using Ocelot.Middleware;
3.ocelot.json 添加json
配置如下:
{
"ReRoutes": [
{
"DownstreamPathTemplate": "/api/values",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 5001
}
],
"UpstreamPathTemplate": "/webapia/values",
"UpstreamHttpMethod": [ "Get" ]
},
{
"DownstreamPathTemplate": "/api/values",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 5002
}
],
"UpstreamPathTemplate": "/webapib/values",
"UpstreamHttpMethod": [ "Get" ]
}
]
}
4.分别修改 launchSettings.json
1.ApiGateway 5000
2.WebApiA 5001
3.WebApiB 5002

修改两个地方就好

最后设置启动项 鼠标 选中解决方案 右键 选择设置启动项

配置完成 看看效果F5 跑起来

大家会发现 为什么
http://localhost:5000/api/values 报错了
那是因为我们配置

因此这个地方 访问咱们需要换一个链接
http://localhost:5000/webapib/values

http://localhost:5000/webapia/values

看步骤大家应该就能猜到为什么会这样运行,具体原理 可以看博园中大神们的注解
Ocelot 新手上路的更多相关文章
- php大力力 [001节]2015-08-21.php在百度文库的几个基础教程新手上路日记 大力力php 大力同学 2015-08-21 15:28
php大力力 [001节]2015-08-21.php在百度文库的几个基础教程新手上路日记 大力力php 大力同学 2015-08-21 15:28 话说,嗯嗯,就是我自己说,做事认真要用表格,学习技 ...
- OpenGL教程之新手上路
Jeff Molofee(NeHe)的OpenGL教程- 新手上路 译者的话:NeHe的教程一共同拥有30多课,内容翔实,而且不断更新 .国内的站点实在应该向他们学习.令人吃惊的是,NeHe提供的例程 ...
- webpack4配置详解之新手上路初探
前言 经常会有群友问起webpack.react.redux.甚至create-react-app配置等等方面的问题,有些是我也不懂的,慢慢从大家的相互交流中,也学到了不少. 今天就尝试着一起来聊 ...
- Dart语言快速学习上手(新手上路)
Dart语言快速学习上手(新手上路) // 声明返回值 int add(int a, int b) { return a + b; } // 不声明返回值 add2(int a, int b) { r ...
- 转-spring-boot 注解配置mybatis+druid(新手上路)-http://blog.csdn.net/sinat_36203615/article/details/53759935
spring-boot 注解配置mybatis+druid(新手上路) 转载 2016年12月20日 10:17:17 标签: sprinb-boot / mybatis / druid 10475 ...
- 活字格企业 Web 应用生成器新手上路指南
活字格是一款企业 Web 应用生成器,使用了类 Excel 的设计界面,通过简单的拖拽操作,就能快速制作出一个 Web 信息管理系统.在整个使用过程中无需专业软件知识,没有任何技术门槛,能轻松实现各行 ...
- Two Sum - 新手上路
不是计算机相关专业毕业的,从来没用过leetcode,最近在学习数据结构和算法,用leetcode练练手. 新手上路,代码如有不妥之处,尽管指出来. 今天抽空做的第一个题:Two Sum(最简单的呃呃 ...
- 新手上路——it人如何保持竞争力
新手上路——如何保持竞争力 JINGZHENGLI 套用葛大爷的一句名言:21世纪什么最贵,人才.哪你是人才还是人材?还是人财或人裁?相信大家都不是最后一种.何如保持住这个光环呢?就需要我们保持我们独 ...
- FreeSql 新手上路系列教程已发布在 cnblogs
FreeSql 是一个功能强大的对象关系映射程序(O/RM),支持 .NETCore 2.1+ 或 .NETFramework 4.5+(QQ群:4336577) FreeSql采用MIT开源协议托管 ...
随机推荐
- WebStorm live edit 浏览器实现同步实现步骤
1.打开WebStore的设置对话框,找到live edit选项,选中Enable live editing. 2.打开Chrome浏览器,进入Chrome网上商店,搜索JetBrains IDE S ...
- How to create a site with AJAX enabled in MVC framework.
How to create a site with AJAX enabled in MVC framework. The Project illustrates how to create a web ...
- 解决Visual Studio Community 2017工具栏中没有Report Viewer的问题
选择“工具”>“Nuget包管理器”>“程序包管理器控制台” 执行命令:Install-Package Microsoft.ReportingServices.ReportViewerCo ...
- RAD C++Builder xe7 std::map xtree BUG
c++Builder 6 下的std::map还能用,有代码提示. 换到xe7,代码提示出来就一个tt.operator [](),代码没法往下写了. 最后把Target Platforms切换到64 ...
- 8 MySQL--单表查询
单表查询: http://www.cnblogs.com/linhaifeng/articles/7267592.html 1.单表查询的语法 2.关键字的执行优先级(重点) 3.简单查询 4.whe ...
- ACM Dance Recital(dfs+剪枝)
The Production Manager of a dance company has been tasked with determining the cost for the seasonal ...
- MVC4中压缩和合并js文件和样式文件
1.在App_Start文件夹中BundleConfig.cs类中添加相应的文件 1.1bundles.Add(new ScriptBundle("~/bundles/adminJs&quo ...
- PC上对限制在微信客户端访问的html页面进行调试
PC上对微信的html5页面做测试,一般来说需要两个条件:浏览器UA改为微信客户端的UA(打开页面提示请在微信客户端登录就需要修改UA):增加满足html5验证条件的Cookie来进行微信OAUTH验 ...
- SpringAop及拦截器
一.Aop Aop,面向切面编程,提供了一种机制,在执行业务前后执行另外的代码. 切面编程包括切面(Aspect),连接点(Joinpoint).通知(Advice).切入点(Pointcut).引入 ...
- Theoretical & Applied Mechanics Letters第2届编委会2015年度第1次全体编委会工作会议纪要(转自力学学会)
2015年7月26日, Theoretical & Applied Mechanics Letters (TAML)第2届编委会在中国科学院力学研究所召开2015年第1次 全体编委工作会议.主 ...