使用Owin Communication听众的状态服务的URL



我使用以下示例为我的 Stateful Service配置通信侦听器:

https://github.com/microsoft/azure-docs/blob/master/articles/service-fabric/service-fabric/service-fabric-reliable-services-services-communication-communication-webapi.md

相关片段:

public Task<string> OpenAsync(CancellationToken cancellationToken)
{
    var serviceEndpoint = this.serviceContext.CodePackageActivationContext.GetEndpoint(this.endpointName);
    var protocol = serviceEndpoint.Protocol;
    int port = serviceEndpoint.Port;
    if (this.serviceContext is StatefulServiceContext)
    {
        StatefulServiceContext statefulServiceContext = this.serviceContext as StatefulServiceContext;
        this.listeningAddress = string.Format(
            CultureInfo.InvariantCulture,
            "{0}://+:{1}/{2}{3}/{4}/{5}",
            protocol,
            port,
            string.IsNullOrWhiteSpace(this.appRoot)
                ? string.Empty
                : this.appRoot.TrimEnd('/') + '/',
            statefulServiceContext.PartitionId,
            statefulServiceContext.ReplicaId,
            Guid.NewGuid());
    }
...

服务清单摘要:

<Endpoints>
  <Endpoint Protocol="http" Name="ServiceEndpoint" Type="Input" Port="8090" />
  <Endpoint Name="ReplicatorEndpoint" />
</Endpoints>

现在,当部署我的应用程序时,我在URL上使用各种GUID进行了服务:

http://localhost:8090/ba794109-BBA3-4CDF-8434-D718BE264087/131407811483781446/614DE30B-14A7-

如果我尝试自行访问http://localhost:8090/,我会遇到错误 503

有什么方法将一般URL映射到主要分区和副本?还是国家服务中不可能?在无状态您将开箱即用。

您所指的"开箱即用"解决方案取决于分区类型。可以通过其服务URL访问Singleton分区:

http://localhost:8090/ApplicationName/ServiceName

这对于具有命名或INT64RANGE分区的服务不起作用,因为URL不参考该服务的特定分区。这就是为什么您必须调用包含GUIDS的服务URL。GUIDS是指分区。

为了解决此问题,您可以使用反向代理。反向代理使您可以通过URL提供分区信息。您可以通过URL调用分区服务:

http(s)://<Cluster FQDN | internal IP>:Port/<ServiceInstanceName>/<Suffix path>?PartitionKey=<key>&PartitionKind=<partitionkind>&ListenerName=<listenerName>&TargetReplicaSelector=<targetReplicaSelector>&Timeout=<timeout_in_seconds>

在您的群集中,它可能看起来像:

http://clusterIP:19081/ApplicationName/ServiceName/PartitionKey=1&PartitionKind=Int64Range

请注意,当前的反向代理(当前(在本地开发群集上不可用。出于开发目的,我建议将URL与GUIDS一起使用,或者将您的分区暂时更改为Singleton计划。

最新更新