- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我将 Ocelot 和 API 网关与 Consul 和服务发现一起使用。我正在 Consul 中使用动态名称注册服务,例如:service.name.1234 和 service.name.5678
此服务是有状态的,根本不需要扩展
因为我在使用 Ocelot,所以我希望能够将请求路由到所需的服务,但是由于名称是动态的,所以我需要使用查询字符串参数作为服务名称
示例:http://myapp.com/service/1234应该重定向到名称为 service.name.1234 的容器
有什么方法可以同时使用这两种产品来实现这一目标?或者其他产品?
谢谢
最佳答案
我一直在寻找相同的解决方案,但只找到一个 comment在 GitHub 上,它对我帮助很大
因此,您需要创建自定义中间件来重写 Ocelot 的 DownstreamRoute:
public static async Task InvokeAsync(HttpContext httpContext, Func<Task> next)
{
var downstreamRoute = httpContext.Items.DownstreamRoute();
var yourServiceName = //get query string parameter from httpContext;
//rewrite any parameter that you want
httpContext.Items.UpsertDownstreamRoute(
new DownstreamRoute(
downstreamRoute.Key,
downstreamRoute.UpstreamPathTemplate,
downstreamRoute.UpstreamHeadersFindAndReplace,
downstreamRoute.DownstreamHeadersFindAndReplace,
downstreamRoute.DownstreamAddresses,
tenantServiceName,
...
));
}
然后在 Startup.cs 中调用它:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// some other code
var configuration = new OcelotPipelineConfiguration
{
PreQueryStringBuilderMiddleware = async (ctx, next) =>
{
await RouteContextRetrieverMiddleware.InvokeAsync(ctx, next);
await next.Invoke();
}
};
app.UseOcelot(configuration).GetAwaiter().GetResult();
}
关于consul - ocelot 和 consul 的动态服务名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53976998/
根据 documentation我尝试合并我的配置文件,以便它们更具可读性。然而,生成的 ocelot.json 文件并不像预期的那样。我的文件夹结构如下: Folder structure 下面是这
我已经将 Ocelot 与 Asp.Net Core 2.1 一起使用并且它可以正常工作,但是当与 Asp.Net Core 3.1 一起使用时它根本不起作用。在我看来,它没有获取“ocelot.js
我已经将 Ocelot 与 Asp.Net Core 2.1 一起使用并且它可以正常工作,但是当与 Asp.Net Core 3.1 一起使用时它根本不起作用。在我看来,它没有获取“ocelot.js
你好现在我正在尝试使用 Ocelot 网关 通常我在不同的服务器上有一个 api https://server_domain.net/kpiDashboardApi 没有网关,如果我直接向下面的链接发
我设计的微服务架构如下: 网关使用 Ocelot 转发请求。我想更改从网关端的移动设备收到的请求中的正文,并在正文中添加新的 GUID。微服务使用 CQRS 模式,因此命令不应返回任何内容。我实现了自
在两个不同的端口上有两个 API。我想用地址 (IP:port ) 来调用它们。为此,我使用了 ocelot api gateway。但是运行程序时,返回如下错误 System.InvalidOper
有什么方法可以将 Ocelot 与多个配置文件和环境一起使用,例如 ocelot.service1.Development.json? 不幸的是,文档似乎已经过时,而且它不处理我的特定请求。我看到它可
我有多个微服务可供客户通过 Ocelot 访问网关。在配置文件中,有一些属性可以指定下游主机和端口。这必须为每条路线完成。 问题是,如果服务的主机名或端口发生变化,我将不得不修改与该特定服务关联的每条
我将 Ocelot 和 API 网关与 Consul 和服务发现一起使用。我正在 Consul 中使用动态名称注册服务,例如:service.name.1234 和 service.name.5678
根据 Ocelot 文档 Quality Of Service我们只能在路由中提及 TimeOutValue,比如 "QoSOptions": { "TimeoutValue":5000 }
我正在使用 ocelot 网关。 这里是示例配置 { "DownstreamPathTemplate": "/ipgeo?apiKey={key}&ip={ip}", "DownstreamS
我正在尝试将 Ocelot 与 IS4 一起使用 https://ocelot.readthedocs.io/en/latest/features/authentication.html 使用时 pu
我必须在 ocelot 身份验证之前对请求的 jwt 进行一些检查,所以我在 PreAuthenticationMiddleware 中进行检查像这样: var config = new Ocelot
有没有办法告诉 Ocelot 一个参数是可选的? 假设下面的查询参数是可选的: "DownstreamPathTemplate": "/api/SearchAPI/?query={query}", "
在将传入的 http 请求转发到下游路径时,我正面临此警告/错误。 Ocelot.DownstreamRouteFinder.Middleware.DownstreamRouteFinderMiddl
我正在尝试在 Api 网关中设置 Ocelot,但我卡在了授权上。我已经设法设置声明,并且可以在我的 Controller 中授权它们。我向这样的用户添加声明: await userManager.A
我正在尝试在 Api 网关中设置 Ocelot,但我卡在了授权上。我已经设法设置声明,并且可以在我的 Controller 中授权它们。我向这样的用户添加声明: await userManager.A
我在我的新项目中实现了 ocelot,我使用 ocelot 在一个点上创建了我的服务集成,但是当我尝试发布、放置、路径或删除到我的 api 网关中的资源时,浏览器向我显示消息 Failed to lo
我使用多个无状态和有状态服务创建了 Azure 服务结构应用程序。我所有的有状态服务都可以通过 Web Api 无状态服务访问。现在,我已将 Ocelot API 网关添加到另一个无状态 Web AP
我使用多个无状态和有状态服务创建了 Azure 服务结构应用程序。我所有的有状态服务都可以通过 Web Api 无状态服务访问。现在,我已将 Ocelot API 网关添加到另一个无状态 Web AP
我是一名优秀的程序员,十分优秀!