Ocelot中文文檔入門

入門

Ocelot僅適用于.NET Core,目前是根據netstandard2.0構建的,如果Ocelot適合您,這個文檔可能會有用。

.NET Core 2.1

安裝NuGet包

使用nuget安裝Ocelot及其依賴項。 您需要創建一個netstandard2.0項目并將其打包到其中。 然后按照下面的“啟動”和“配置”部分啟動并運行。

Install-Package?Ocelot

所有版本都可以在這里找到。

配置

以下是一個非常基本的ocelot.json。 它不會做任何事情,但應該讓Ocelot開始。

{"ReRoutes": [],"GlobalConfiguration": {"BaseUrl": "https://api.mybusiness.com"}
}

這里要注意的最重要的是BaseUrl。 Ocelot需要知道它正在運行的URL,以便執行Header查找和替換以及某些管理配置。 設置此URL時,它應該是客戶端將看到運行Ocelot的外部URL,例如 如果你正在運行容器,Ocelot可能會在網址http://123.12.1.1:6543上運行,但在https://api.mybusiness.com上響應它之前有類似nginx的東西。 在這種情況下,Ocelot基本網址應為https://api.mybusiness.com。?

如果由于某種原因你正在使用容器并且希望Ocelot在http://123.12.1.1:6543上響應客戶端,那么你可以這樣做但是如果要部署多個Ocelot,你可能希望在命令行中傳遞它 某種腳本。 希望您使用的任何調度程序都可以傳遞IP。
?
Program.cs文件
然后在Program.cs中,您將需要以下內容。 需要注意的主要事項是AddOcelot()(添加ocelot服務),UseOcelot()。Wait()(設置所有Ocelot中間件)。
 
public class Program
{public static void Main(string[] args){new WebHostBuilder().UseKestrel().UseContentRoot(Directory.GetCurrentDirectory()).ConfigureAppConfiguration((hostingContext, config) =>{config.SetBasePath(hostingContext.HostingEnvironment.ContentRootPath).AddJsonFile("appsettings.json", true, true).AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true, true).AddJsonFile("ocelot.json").AddEnvironmentVariables();}).ConfigureServices(s => {s.AddOcelot();}).ConfigureLogging((hostingContext, logging) =>{//add your logging
            }).UseIISIntegration().Configure(app =>{app.UseOcelot().Wait();}).Build().Run();}
}

.NET Core 1.0

安裝NuGet包

使用nuget安裝Ocelot及其依賴。 您需要創建一個netcoreapp1.0 + projct并將包帶入其中。 然后按照下面的“啟動”和“配置”部分啟動并運行。 請注意,您需要從NuGet Feed中選擇一個Ocelot包。

所有版本都可以在這里找到。
配置
?
以下是一個非常基本的ocelot.json。 它不會做任何事情,但應該讓Ocelot開始。
?
{{ "ReRoutes": [],"GlobalConfiguration": {}
}

?

Program.cs文件
?
然后在Program.cs中,您將需要以下內容。
?
public class Program
{public static void Main(string[] args){IWebHostBuilder builder = new WebHostBuilder();builder.ConfigureServices(s => {});builder.UseKestrel().UseContentRoot(Directory.GetCurrentDirectory()).UseStartup<Startup>();var host = builder.Build();host.Run();}
}
Startup.cs文件使用json文件進行配置的示例啟動如下所示。public class Startup
{public Startup(IHostingEnvironment env){var builder = new ConfigurationBuilder().SetBasePath(env.ContentRootPath).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true).AddJsonFile("ocelot.json").AddEnvironmentVariables();Configuration = builder.Build();}public IConfigurationRoot Configuration { get; }public void ConfigureServices(IServiceCollection services){services.AddOcelot(Configuration);}public void Configure(IApplicationBuilder app){app.UseOcelot().Wait();}
}
以上這些就是Ocelot基本入門內容。喜歡就收藏此文。版權所有,禁止未經授權的復制轉載。詳細的中文文檔查閱 http://nopapp.com/Blog/Article/Ocelot-Basic

轉載于:https://www.cnblogs.com/bruceday/p/9872584.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/388104.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/388104.shtml
英文地址,請注明出處:http://en.pswp.cn/news/388104.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

科學價值 社交關系 大數據_服務的價值:數據科學和用戶體驗研究美好生活

科學價值 社交關系 大數據A crucial part of building a product is understanding exactly how it provides your customers with value. Understanding this is understanding how you fit into the lives of your customers, and should be central to how you build on wha…

在Ubuntu下創建hadoop組和hadoop用戶

一、在Ubuntu下創建hadoop組和hadoop用戶 增加hadoop用戶組&#xff0c;同時在該組里增加hadoop用戶&#xff0c;后續在涉及到hadoop操作時&#xff0c;我們使用該用戶。 1、創建hadoop用戶組 2、創建hadoop用戶 sudo adduser -ingroup hadoop hadoop 回車后會提示輸入新的UNIX…

day06 hashlib模塊

1.hashlib模塊 import hashlib# password123456# print( password.encode()) #加密前先轉成二進制# mhashlib.md5(password.encode())# print(dir(m)) #查詢m的所有方法## print(m.hexdigest()) #使用hexdigest()方法加密&#xff0c;md5加密之后是不可逆&#xff0c;不可以解…

vs azure web_在Azure中遷移和自動化Chrome Web爬網程序的指南。

vs azure webWebscraping as a required skill for many data-science related jobs is becoming increasingly desirable as more companies slowly migrate their processes to the cloud.隨著越來越多的公司將其流程緩慢遷移到云中&#xff0c;將Web爬網作為許多與數據科學相…

hadoop eclipse windows

首先說一下本人的環境: Windows7 64位系統 Spring Tool Suite Version: 3.4.0.RELEASE Hadoop2.6.0 一&#xff0e;簡介 Hadoop2.x之后沒有Eclipse插件工具&#xff0c;我們就不能在Eclipse上調試代碼&#xff0c;我們要把寫好的java代碼的MapReduce打包成jar然后在Linux上運…

同步函數死鎖現象

多線程&#xff1a;一個進程中有多個線程可以同時執行任務 多線程的好處&#xff1a; 1、解決一個進程中可以同時執行多個任務的問題。 2、提高了資源利用率 多線程的弊端&#xff1a; 1、增加了CPU的負擔 2、降低了一個進程中線程的執行概率 3、出現了線程安全問題 4、會引發死…

netstat 在windows下和Linux下查看網絡連接和端口占用

假設忽然起個服務&#xff0c;告訴我8080端口被占用了&#xff0c;OK&#xff0c;我要去看一下是什么服務正在占用著&#xff0c;能不能殺 先假設我是在Windows下&#xff1a; 第一列&#xff1a; Proto 協議 第二列&#xff1a; 本地地址【ip端口】 第三列&#xff1a;遠程地址…

selenium 解析網頁_用Selenium進行網頁搜刮

selenium 解析網頁網頁抓取系列 (WEB SCRAPING SERIES) 總覽 (Overview) Selenium is a portable framework for testing web applications. It is open-source software released under the Apache License 2.0 that runs on Windows, Linux and macOS. Despite serving its m…

表的設計與優化

單表設計與優化 1&#xff09;設計規范化表&#xff0c;消除數據冗余&#xff08;以使用正確字段類型最明顯&#xff09;&#xff1a; 數據庫范式是確保數據庫結構合理&#xff0c;滿足各種查詢需要、避免數據庫操作異常的數據庫設計方式。滿足范式要求的表&#xff0c;稱為規范…

代理ARP協議(Proxy ARP)

代理ARP&#xff08;Proxy-arp&#xff09;的原理就是當出現跨網段的ARP請求時&#xff0c;路由器將自己的MAC返回給發送ARP廣播請求發送者&#xff0c;實現MAC地址代理&#xff08;善意的欺騙&#xff09;&#xff0c;最終使得主機能夠通信。 圖中R1和R3處于不同的局域網&…

hive 導入hdfs數據_將數據加載或導入運行在基于HDFS的數據湖之上的Hive表中的另一種方法。

hive 導入hdfs數據Preceding pen down the article, might want to stretch out appreciation to all the wellbeing teams beginning from cleaning/sterile group to Nurses, Doctors and other who are consistently battling to spare the mankind from continuous Covid-1…

Java性能優化

一、避免在循環條件中使用復雜表達式 在不做編譯優化的情況下&#xff0c;在循環中&#xff0c;循環條件會被反復計算&#xff0c;如果不使用復雜表達式&#xff0c;而使循環條件值不變的話&#xff0c;程序將會運行的更快。 例子&#xff1a; import java.util.vector; class …

對Faster R-CNN的理解(1)

目標檢測是一種基于目標幾何和統計特征的圖像分割&#xff0c;最新的進展一般是通過R-CNN&#xff08;基于區域的卷積神經網絡&#xff09;來實現的&#xff0c;其中最重要的方法之一是Faster R-CNN。 1. 總體結構 Faster R-CNN的基本結構如下圖所示&#xff0c;其基礎是深度全…

大數據業務學習筆記_學習業務成為一名出色的數據科學家

大數據業務學習筆記意見 (Opinion) A lot of aspiring Data Scientists think what they need to become a Data Scientist is :許多有抱負的數據科學家認為&#xff0c;成為一名數據科學家需要具備以下條件&#xff1a; Coding 編碼 Statistic 統計 Math 數學 Machine Learni…

postman 請求參數為數組及JsonObject

2019獨角獸企業重金招聘Python工程師標準>>> 1. (1)數組的請求方式(post) https://blog.csdn.net/qq_21205435/article/details/81909184 (2)數組的請求方式&#xff08;get&#xff09; http://localhost:port/list?ages10,20,30 后端接收方式&#xff1a; PostMa…

領扣(LeetCode)對稱二叉樹 個人題解

給定一個二叉樹&#xff0c;檢查它是否是鏡像對稱的。 例如&#xff0c;二叉樹 [1,2,2,3,4,4,3] 是對稱的。 1/ \2 2/ \ / \ 3 4 4 3但是下面這個 [1,2,2,null,3,null,3] 則不是鏡像對稱的: 1/ \2 2\ \3 3說明: 如果你可以運用遞歸和迭代兩種方法解決這個問題&#…

python 開發api_使用FastAPI和Python快速開發高性能API

python 開發apiIf you have read some of my previous Python articles, you know I’m a Flask fan. It is my go-to for building APIs in Python. However, recently I started to hear a lot about a new API framework for Python called FastAPI. After building some AP…

Purley平臺Linpak測試,從踏坑開始一步步優化

Purley平臺Linpak測試&#xff0c;從踏坑開始一步步優化 #記2017年11月第一次踏坑事件 測試平臺配置&#xff1a; 6nodes CPU: Intel Gold 6132 2.6GHz 14C RAM: 8G *12 2666MHz NET: Infiband FDR OS: centos7.2 mpi: Intel-mpi hpl: xhpl.intel 開始踏第一坑 現象&#xff1a…

基于easyui開發Web版Activiti流程定制器詳解(一)——目錄結構

&#xfeff;&#xfeff;題外話&#xff08;可略過&#xff09;&#xff1a; 前一段時間&#xff08;要是沒記錯的話應該是3個月以前&#xff09;發布了一個更新版本&#xff0c;很多人說沒有文檔看著比較困難&#xff0c;所以打算拿點時間出來詳細給大家講解一下&#xff0c;…

HDOJ 2037:今年暑假不AC_大二寫

AC代碼&#xff1a; #include <iostream> #include <cstdio> #include <algorithm> #define Max 105 using namespace std;struct TimeList {int start;int end; }timelist[Max]; bool compare(TimeList a, TimeList b) {if(a.end b.end)return a.start &l…