首页 > 其他分享 >Ocelot+Consul的使用配置

Ocelot+Consul的使用配置

时间:2024-02-12 19:23:11浏览次数:26  
标签:8500 http Consul 配置 Port Ocelot builder localhost

客户端
代码配置 "ConsulRegisterOptions": { "Address": "http://localhost:8500", //"http://host.docker.internal:8500", //Consul 客户端地址 "HealthCheck": "/healthcheck", //健康检查地址 "Name": "ServiceA", //服务名 "Ip": "localhost", //"host.docker.internal", //服务绑定Ip "Port": "5032" //服务绑定端口 } 代码配置 "ConsulRegisterOptions": { "Address": "http://localhost:8500", //"http://host.docker.internal:8500", //Consul 客户端地址 "HealthCheck": "/healthcheck", //健康检查地址 "Name": "ServiceA", //服务名 "Ip": "localhost", //"host.docker.internal", //服务绑定Ip "Port": "5096" //服务绑定端口 } 这里用于ocelot切换,两个项目

  

客户端
builder.Services.Configure<ConsulRegisterOptions>(builder.Configuration.GetSection("ConsulRegisterOptions")); builder.Services.AddConsulRegister();

  

app.UseHealthCheckMiddleware();

app.MapGet("/test", (IConfiguration configuration) =>
{
    return $"{Assembly.GetExecutingAssembly().FullName};当前时间:{DateTime.Now:G};Port:{configuration["ConsulRegisterOptions:Port"]}";
});

await app.Services.GetService<IConsulRegister>()!.ConsulRegistAsync();
ocelot端
{ "Routes": [ { "DownstreamPathTemplate": "/{url}", //下游(转发的服务地址模板) "DownstreamScheme": "http", "UpstreamPathTemplate": "/ocelot/{url}", //上游(请求路径模板) "UpstreamHttpMethod": [ "Get", "Post" ], "ServiceName": "ServiceA", "UseServiceDiscovery": true, "LoadBalancerOptions": { "Type": "RoundRobin" //轮询 } } ], "GlobalConfiguration": { "BaseUrl": "http://localhost:5181", "ServiceDiscoveryProvider": { //consul 配置信息 "Host": "localhost", "Port": 8500, "Type": "Consul" } } }

builder.Configuration.AddJsonFile("ocelot.json", optional: false, reloadOnChange: true);
builder.Services.AddOcelot().AddConsul();


await app.UseOcelot();

 

 

标签:8500,http,Consul,配置,Port,Ocelot,builder,localhost
From: https://www.cnblogs.com/liujian1368928/p/18014043

相关文章

  • kube-apiserver限流配置
    k8sv1.19.0APF之前限流客户端访问kube-apiserver,限流参数有max-mutating-requests-inflight(默认值是200,对应操作类请求)和max-requests-inflight(默认值是400,对应查询类请求)。staging/src/k8s.io/apiserver/pkg/server/filters/maxinflight.goWithMaxInFlightLimit函数分别创建......
  • 1.微服务注册中心Consul
     Consul是HashiCorp公司推出的开源工具,Consul由Go语言开发,部署起来非常容易,只需要极少的可执行程序和配置文件,具有绿色、轻量级的特点。Consul是分布式的、高可用的、可横向扩展的用于实现分布式系统的服务发现与配置。中文网:Consul中文文档-Consul中文文档(gitb......
  • Vite+Vue根据环境配置Websocket地址
    前言上回说到,利用vite加载不同mode下的配置文件,可以实现不同运行环境下的参数配置。在前端应用中经常使用到Websocket,其地址同样可以在.env中间中配置。代码vite.config.ts代码的执行是在createApp之前,不可以在vite.config.ts中使用例如pinia、router等组件。可以使用import.me......
  • python3.9 + django4.1 + vue3 ,报错,无法访问配置的路由地址,Using the URLconf defined
    python3.9+django4.1+vue3,报错,无法访问配置的路由地址,UsingtheURLconfdefinedinStudentMgrBE.urls,DjangotriedtheseURLpatterns,inthisorder:-------------------------------------------------------------------------------无法访问 地址,报错如下: Us......
  • nginx容器配置方案
    nginx容器配置可以参考docker官网nginx页面的默认配置docker-nginx官网howtouseimage这里面提供了一些demo,可以帮助我们快速的启动nginx容器,并且除了常规的挂载、端口等基本配置外,还提供了以只读方式启动、以debug模式启动、设置日志等级环境变量等演示。下文仅是博主根据......
  • Vite+Vue3项目如何获取环境配置,并解决前端跨域问题
    步骤根目录新建.env.development和.env.production文件package.json配置启动参数vite命令启动项目时,指定mode参数,加载vite.config.ts文件。"dev":"vite--host0.0.0.0--port8093--modedevelopment","prod":"vite--port8093--host0.0.0.0--modepr......
  • 8小时速成Golang(二)Golang开发环境 环境配置
     Go官网下载地址:https://golang.org/dl/Go官方镜像站(推荐):https://golang.google.cn/dl/Go官网:https://golang.org/ golang在Windows安装和配置可看链接:https://blog.csdn.net/weixin_54626591/article/details/134485077按照步骤一步一步next再配置环境变量即可 golan......
  • 虚拟机连接与网络配置问题
    记得刚接触取证那会儿,连最基本的虚拟机连接ssh都不行,现在想想自学网安的一年时间里,从完全不知道的小白到至少简简单单入了个门!学不可以已!接下来的一年,需要花更多的时间,不断学习,不断进步!龙年加油!虚拟机的网络连接问题虚拟机的三种网络配置模式 linux(以Centos为例)网络配......
  • 7.读写配置文件和添加缓存
    感觉没什么好总结的,直接上代码吧:配置文件:1添加一个枚举///<summary>///配置键名///</summary>publicenumConfigKey{///<summary>///系统配置///</summary>SystemConfig,///<summary>......
  • [Kyana]一些AI应用的配置
    01|stable-diffusion画图使用秋叶的启动器,自动下载python、torch和source复制链接下载SD模型,调节参数启动webui使用提示词插件(sd-webui-prompt-all-in-one)和汉化插件(stable-diffusion-webui-localization-zh_CN)02|KataGo围棋使用界面Sabaki,引擎katago,权重b18选择katago版......