首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用OCELOT的API网关-错误-无法启动Ocelot

使用OCELOT的API网关-错误-无法启动Ocelot
EN

Stack Overflow用户
提问于 2018-07-21 17:59:11
回答 2查看 9.2K关注 0票数 1

我是API网关的新手,首先遵循下面的链接。

https://www.c-sharpcorner.com/article/building-api-gateway-using-ocelot-in-asp-net-core/

当我试图运行应用程序时,它会在下面的代码行中在Startup.cs文件中抛出一个错误。

Startup.cs

代码语言:javascript
复制
public Startup(IHostingEnvironment env){
    var builder = new Microsoft.Extensions.Configuration.ConfigurationBuilder();
    builder.SetBasePath(env.ContentRootPath)
    .AddJsonFile("configuration.json", optional: false, reloadOnChange: true)
    .AddEnvironmentVariables();
    Configuration = builder.Build();
}

public IConfigurationRoot Configuration { get; }

public void ConfigureServices(IServiceCollection services){
    Action<ConfigurationBuilderCachePart> settings = (x) =>{
        x.WithMicrosoftLogging(log =>{
            log.AddConsole(LogLevel.Debug);
        }).WithDictionaryHandle();
    };
    //services.AddOcelot(Configuration, settings);
    services.AddOcelot(Configuration);
}

public async void Configure(IApplicationBuilder app, IHostingEnvironment env){
    await app.UseOcelot();  // Error in this line number
}
}

错误:

无法启动Ocelot,错误是:当不使用服务发现时,必须设置DownstreamHostAndPorts而不是空,或者Ocelot不能找到您的服务!当不使用服务发现DownstreamHostAndPorts时,必须设置且不为空,或者Ocelot无法找到您的服务!

configuration.json

代码语言:javascript
复制
{</br>
    "ReRoutes": [</br>
        {</br>
            "DownstreamPathTemplate": "/api/customers",
            "DownstreamScheme": "http",
            "DownstreamHost": "localhost",
            "DownstreamPort": 9001,
            "UpstreamPathTemplate": "/customers",
            "UpstreamHttpMethod": [ "Get" ]</br>
        },</br>
        {</br>
            "DownstreamPathTemplate": "/api/customers/{id}",
            "DownstreamScheme": "http",
            "DownstreamHost": "localhost",
            "DownstreamPort": 9001,
            "UpstreamPathTemplate": "/customers/{id}",
            "UpstreamHttpMethod": [ "Get" ]</br>
        },</br>
        {</br>
            "DownstreamPathTemplate": "/api/products",
            "DownstreamScheme": "http",
            "DownstreamPort": 9002,
            "DownstreamHost": "localhost",
            "UpstreamPathTemplate": "/api/products",
            "UpstreamHttpMethod": [ "Get" ]</br>
        }</br>
    ],</br>
    "GlobalConfiguration": {
        "RequestIdKey": "OcRequestId",
        "AdministrationPath": "/administration"
    }</br>
}</br></br>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-07-27 07:32:48

我使用了Ocelot8.0.1,这个版本有一个错误。升级到8.0.2,现在工作正常。

票数 0
EN

Stack Overflow用户

发布于 2018-07-25 12:00:49

您似乎已经更新了最新的Ocelot包,因此您的configuration.json文件不正确。请参考- http://ocelot.readthedocs.io/en/latest/features/routing.html

您需要将DownStreamHost/Port设置为:

代码语言:javascript
复制
"DownstreamHostAndPorts": [
      {
        "Host": "localhost",
        "Port": 9001
      }
    ],
票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51458714

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档