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/