CondenserDotNet - 使用 Kestrel 和 Consul 的 API 反向代理库!
生活随笔
收集整理的這篇文章主要介紹了
CondenserDotNet - 使用 Kestrel 和 Consul 的 API 反向代理库!
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
簡介
CondenserDotNet - 使用 Kestrel 和 Consul 的 API 反向代理庫!
特點
?Consul 客戶端庫,包括服務(wù)注冊、發(fā)現(xiàn)和配置?反向代理?交互式 UI,用于查看有關(guān)代理的統(tǒng)計信息
配置示例
配置遵循 LIFO 策略,以最后注冊的配置為準
var?configValue?=?configRegistry["MyKey"];如果密鑰不存在,它將引發(fā)異常。您也可以使用普通的 tryget 模式訪問它
if(configRegistry.TryGetValue("MyKey",?out?string?configValue)) {//do?something?with?the?key }靜態(tài)配置
要注冊一組靜態(tài)鍵,請使用以下代碼
var?result?=?await?configRegistry.AddStaticKeyPathAsync("my/keys/path");動態(tài)配置
可以注冊動態(tài)配置的關(guān)鍵路徑,代碼如下
var?registry?=?new?ConsulRegistry();await?registry.AddUpdatingPathAsync("org/test5/");還可以注冊回調(diào)以提醒您是否更新了特定鍵或配置中的任何鍵是否已更新。
var?singleCallBack?=?registry.AddWatchOnSingleKey("test1",?()?=>?Console.Writeline("Key?Changed!");如果您想要任何更新來觸發(fā)您的回調(diào),只需執(zhí)行
var?multipleCallBack?=?registry.AddWatchOnEntireConfig(()?=>?Console.Writeline("Some?key?changed,?or?multiple?keys?changed,?or?maybe?none?");請求服務(wù)
獲取要連接的服務(wù)實例的示例
var?serviceInstance?=?await?serviceRegistry.GetServiceInstanceAsync("ServiceLookup"); if(serviceInsance?==?null) {//you?need?to?handle?no?service?instance?available } //connect?to?service?via?your?method var?serverUrl?=?$"http://{serviceInstance.Address}:{serviceInsance.Port}";//your?method?for?calling?servers服務(wù)端口
在動態(tài)端口上配置 Kestrel 的示例
var?host?=?new?WebHostBuilder().UseKestrel().UseUrls($"http://*:{ServiceManagerOptions.GetNextAvailablePort()}").UseStartup<Startup>().Build();host.Run();服務(wù)注冊
在動態(tài)端口上配置 Kestrel 的示例
var?host?=?new?WebHostBuilder().UseKestrel().UseUrls($"http://*:{serviceManager.ServicePort}").UseStartup<Startup>().Build();host.Run();Github地址
https://github.com/Drawaes/CondenserDotNet
最后大家如果喜歡我的文章,還麻煩給個關(guān)注并點個贊, 希望net生態(tài)圈越來越好!
總結(jié)
以上是生活随笔為你收集整理的CondenserDotNet - 使用 Kestrel 和 Consul 的 API 反向代理库!的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 我将 20 年前开发的操作系统迁移到 .
- 下一篇: 如何使用GeneralUpdte构建客户