入門
オセロットは現在netstandard2.0構築され、.NETのコアでのみ使用可能です。オセロットがあなたのために右である場合、この文書は有用である可能性があります。
。ネット
NuGetのインストールパッケージ
nugetインストールオセロットとその依存関係を使用してください。あなたはnetstandard2.0プロジェクトを作成し、それにそれらをパッケージ化する必要があります。そして、「開始」と「追跡 の設定」セクションの稼働を。
Install-Package Ocelot
すべてのバージョンは、することができ、ここで見つかりました。
コンフィギュレーション
以下は、非常に基本的なocelot.jsonです。それは何もしますが、オセロットを開始すべきことはできません。
{
"ReRoutes": [],
"GlobalConfiguration": { "BaseUrl": "https://api.mybusiness.com" } }
ここで注意すべき最も重要なことはBASEURLです。ヘッダーは、検索と置換、および特定の管理構成のためオセロットは、それが実行されているURLを知っている必要があります。あなたはこのURLを設定すると、クライアントはあなたがコンテナを実行している場合、オセロットはURL上で実行する可能性がある、例えば、オセロット外部URLを実行している表示されますする必要があります http://123.12.1.1:6543 が、同様の前ででnginxの応答のHTTPS 応答://api.mybusiness.com。この場合、オセロットのベースURLをすべき https://api.mybusiness.com 。
あなたは、コンテナを使用し、中オセロットを必要としている場合http://123.12.1.1:6543 クライアントへの応答、 あなたはこれを行うことができますが、複数のオセロットを展開する場合は、コマンドラインのいくつかのタイプに合格することをお勧めしますそのスクリプト。あなたは、任意のスケジューリングプログラムを使用したいIPを介して利用できます。
プログラム
次に、あなたのProgram.csでは、次が必要になります。注意すべき主な点は、AddOcelot()(オセロット付加価値サービス)、UseOcelot()です。待って()(オセロットは、すべてのミドルウェアを設定します)。
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();
}
}
**Note:** When using ASP.NET Core 2.2 and you want to use In-Process hosting, replace **.UseIISIntegration()** with **.UseIIS()**, otherwise you'll get startup errors.
。ネット
NuGetのインストールパッケージ
nugetインストールオセロットとその依存関係を使用してください。あなたはnetcoreapp1.0 + projctを作成し、それらにパックする必要があります。そして、「開始」と「追跡 の設定」セクションの稼働を。あなたはNuGetはオセロットフィードからパッケージを選択する必要がありますのでご注意ください。
すべてのバージョンは、することができ、ここで見つかりました。
コンフィギュレーション
以下は、非常に基本的なocelot.jsonです。それは何もしますが、オセロットを開始すべきことはできません。
{
"ReRoutes": [],
"GlobalConfiguration": {} }
プログラム
次に、あなたの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(); } }
スタート
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();
}
}
それはほとんどすべてあなたが始めるために必要です。