consul ocelot
consul配置完成后
新建.netcoreapi项目,
nuget安装ocelot
添加多个配置文件,.netcore中会自动合并为一个文件,global配置总的配置,其他为各个项目的配置

ServiceName为consul中配置的服务名称:
{
"ReRoutes": [
{
"DownstreamPathTemplate": "/Api/{everything}",
"DownstreamScheme": "http",
"UpstreamPathTemplate": "/Api/{everything}",
"UpstreamHttpMethod": [ "Get", "Post" ],
"LoadBalancerOptions": {
//"Type": "RoundRobin",
"Type": "LeastConnection"
},
"ServiceName": "Api",
"UseServiceDiscovery ": true
}
]
}
配置服务发现:ocelot.global.json
{
"GlobalConfiguration": {
"ServiceDiscoveryProvider": {
"Host": "47.92.80.220",
"Port": ,
"Type": "Consul"
}
}
}
在program.cs中添加json文件,注意AddOcelot
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext, config) =>
{
config
.SetBasePath(hostingContext.HostingEnvironment.ContentRootPath)
//.AddJsonFile("appsettings.json", true, true)
.AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true, true)
.AddOcelot( hostingContext.HostingEnvironment)
.AddEnvironmentVariables();
})
//.UseUrls("http://localhost:1000")
.UseStartup<Startup>();
在startup.cs的ConfigureServices中注入
services.AddOcelot(Configuration)
.AddConsul();
在Configure中
app.UseOcelot().Wait();
至此就完成了配置,启动项目后根据配置的路由找到ServiceName,然后会访问服务发现中的路由
consul ocelot的更多相关文章
- windows环境下如何搭建Consul+Ocelot
下面的是markdown格式的文档,懒得排版了,有兴趣的话可以去github上看,有源码 Github:https://github.com/yuchengao0721/Consul-Ocelot.g ...
- Consul+Ocelot+Polly在.NetCore中使用(.NET5)-网关Ocelot+Consul
相关文章 Consul+Ocelot+Polly在.NetCore中使用(.NET5)-Consul服务注册,服务发现 Consul+Ocelot+Polly在.NetCore中使用(.NET5)-网 ...
- Consul+Ocelot+Polly在.NetCore中使用(.NET5)-Ocelot+Polly缓存、限流、熔断、降级
相关文章 Consul+Ocelot+Polly在.NetCore中使用(.NET5)-Consul服务注册,服务发现 Consul+Ocelot+Polly在.NetCore中使用(.NET5)-网 ...
- Consul+Ocelot+Polly在.NetCore中使用(.NET5)-Consul服务注册,服务发现
环境 .NET5,Consul_v1.10.2 一.简介 在微服务中利用Consul可以实现服务的注册,服务发现,治理,健康检查等. Web调站点需要调用多个服务,如果没有Consul,可能就是Web ...
- Ocelot + Consul实践
关于Consul(https://www.consul.io)是一个分布式,高可用,支持多数据中心的服务发现和配置共享的服务软件,由 HashiCorp 公司用 Go 语言开发, 基于 Mozilla ...
- .NET5 API 网关Ocelot+Consul服务注册
1|0网关介绍 网关其实就是将我们写好的API全部放在一个统一的地址暴露在公网,提供访问的一个入口.在 .NET Core下可以使用Ocelot来帮助我们很方便的接入API 网关.与之类似的库还有Pr ...
- .NET微服务从0到1:服务注册与发现(Consul)
目录 Consul搭建 基于Docker搭建Consul 基于Windows搭建Consul ServiceA集成Consul做服务注册 Ocelot集成Consul做服务发现 更多参考 Consul ...
- .NetCore·集成Ocelot组件之完全解决方案
阅文时长 | 11.04分钟 字数统计 | 17672.8字符 主要内容 | 1.前言.环境说明.预备知识 2.Ocelot基本使用 3.Ocelot功能挖掘 4.Ocelot集成其他组件 5.避坑指 ...
- 微服务网关Ocelot加入IdentityServer4鉴权-.NetCore(.NET5)中使用
Consul+Ocelot+Polly在.NetCore中使用(.NET5)-Consul服务注册,服务发现 Consul+Ocelot+Polly在.NetCore中使用(.NET5)-网关Ocel ...
随机推荐
- BootStrap【二、样式】
H5文档类型 由于使用了H5和CSS熟悉,需要在文件头引入 移动设备优先 为了对移动设备友好,需要使用标签viewport width=device-width 宽度为设备宽度 height 高度 i ...
- 解决IDEA提示Untrusted Server's certificate 证书不可用( Server's certificate is not trusted )
Untrusted Server's certificate 如果你用的是Intellij系列IDE(GoLand, PHPStorm, WebStorm, IDEA),突然弹出个提示『Untrust ...
- python笔记:学习设置Python虚拟环境+配置 virtualenvwarpper+创建Python3.6的虚拟环境+安装numpy
虚拟环境它是一个虚拟化,从电脑独立开辟出来的环境.就是借助虚拟机docker来把一部分内容独立出来,我们把这部分独立出来的东西称作“容器”,在这个容器中,我们可以只安装我们需要的依赖包,各个容器之间互 ...
- Ubuntu下PHP+MySQL+Apache+PHPStorm的安装和配置
粘贴自:https://www.jianshu.com/p/a6a0d2a29591 1.Apache的安装: $ sudo apt-get update $ sudo apt-get install ...
- 说一下 HashSet 的实现原理?(未完成)
说一下 HashSet 的实现原理?(未完成)
- Springboot静态资源映射 “/” 引发的血案
因为少写一个 / 浪费已个下午的时间,
- Zabbix Web 中文字体显示问题
- 调用WebService接口返回字符串
Service service = new Service(); Call call = (Call) service.createCall(); call.setTargetEndpointAddr ...
- vue 01 练习
1.有 红.黄.蓝 三个按钮,以及一个200x200矩形框box,点击不同的按钮,box的颜色会被切换为指定的颜色 <!DOCTYPE html> <html lang=" ...
- linux 下python进程查看及关闭
查看进程 ps -ef |grep python 关闭进程 kill -9 26879 其中26879为进程号. linux下后台执行某个python脚本 nohup python -u xxx.py ...