c# - 我什么时候应该使用 ServiceFabricIntegrationOptions.UseUniqueServiceUrl

标签 c# azure asp.net-core azure-service-fabric

This似乎是说这始终是必要的,否则您可能会解决不正确的服务 - 因为不能保证服务不会移动等...

默认的asp.net core服务模板使用 UseServiceFabricIntegration(监听器,ServiceFabricIntegrationOptions.None)

这有什么原因吗?什么时候可以不使用 ServiceFabricIntegration 中间件?

<小时/>

E:我看到这些实际上是一个标志枚举。因此,您可能应该始终使用 UseUniqueServiceUrl https://github.com/Azure/service-fabric-aspnetcore/blob/develop/src/Microsoft.ServiceFabric.AspNetCore/WebHostBuilderServiceFabricExtension.cs

最佳答案

恕我直言,我认为您没有充分阅读这些文档。解释得很好here :

Services that use a dynamically-assigned port should make use of this middleware.

Services that use a fixed unique port do not have this problem in a cooperative environment. A fixed unique port is typically used for externally-facing services that need a well-known port for client applications to connect to. For example, most Internet-facing web applications will use port 80 or 443 for web browser connections. In this case, the unique identifier should not be enabled.

总结一下:在使用 Kestrel 或 WebListener 时,您可以选择使用动态端口或固定端口。请参阅上述链接中的使用带有静态端口的 WebListener/Kestrel使用带有动态端口的 WebListener/Kestrel 部分。当您选择使用动态端口时,请使用 ServiceFabricIntegrationOptions.UseUniqueServiceUrl,否则使用 ServiceFabricIntegrationOptions.None 作为中间件的参数。

现在,至于为什么在动态端口的情况下需要这个独特的服务 url 中间件,有一个场景描述了可能的问题:

If services use dynamically-assigned application ports, a service replica may coincidentally use the same IP:port endpoint of another service that was previously on the same physical or virtual machine. This can cause a client to mistakely connect to the wrong service. This can happen if the following sequence of events occur:

  • Service A listens on 10.0.0.1:30000 over HTTP.
  • Client resolves Service A and gets address 10.0.0.1:30000
  • Service A moves to a different node.
  • Service B is placed on 10.0.0.1 and coincidentally uses the same port 30000.
  • Client attempts to connect to service A with cached address 10.0.0.1:30000.
  • Client is now successfully connected to service B not realizing it is connected to the wrong service.

This can cause bugs at random times that can be difficult to diagnose

关于c# - 我什么时候应该使用 ServiceFabricIntegrationOptions.UseUniqueServiceUrl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43679057/

相关文章:

c# - 从 ServiceStack WSDL 中移除 swagger

C# 从另一个线程上调用的委托(delegate)捕获异常

c# - 如何返回 Visual Studio 当前打开的 sotion 目录

c# - 在 C# 中拦截对属性 get 方法的调用

azure - 有没有办法将免费套餐折扣应用于现有的 CosmosDB 资源?

azure - 使用专用端点与服务端点从 vnet/子网访问相同服务的多个实例

azure - 如何让 Azure 应用服务在静态站点上添加自定义 HTTP 响应 header ?

c# - 如何从 .NET Core 应用程序的其他层访问 IOptions(或任何设置)?

asp.net-core - 获取分配角色的用户

c# - 如何使用 .NET 6 最小 API 将 wwwroot 目录下的文件路径作为 URL 返回?