【问题标题】:URL of Stateful Service using OWIN communication listener使用 OWIN 通信侦听器的 Stateful Service 的 URL
【发布时间】:2017-11-02 08:17:36
【问题描述】:

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

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

相关sn-p:

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());
    }
...

服务清单 sn-p:

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

现在在部署我的应用程序时,我可以通过各种 guid 在 URL 上获取服务:

http://localhost:8090/ba794109-bba3-4cdf-8434-d718be264087/131407811483781446/614de30b-14a7-4172-a03d-4e28d23cf28d

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

有什么方法可以将通用 URL 映射到主分区和副本?或者在有状态服务中是不可能的?在 Stateless 中,您可以立即使用它。

【问题讨论】:

    标签: c# routes owin azure-service-fabric service-fabric-stateful


    【解决方案1】:

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

    http://localhost:8090/ApplicationName/ServiceName
    

    这不适用于具有 Named 或 Int64Range 分区的服务,因为 URL 不引用服务的特定分区。这就是为什么您必须调用包含 GUID 的服务 URL。 GUID 指的是分区。

    为了解决这个问题,您可以使用reverse proxy。反向代理允许您通过 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
    

    请注意,反向代理(当前)在本地开发集群上不可用。出于开发目的,我建议使用带有 GUID 的 URL,或者暂时将分区更改为单例方案。

    【讨论】:

    • 如果我使用单例分区,我将如何处理 ReplicaId GUID?
    • 无论何时调用该服务,您的调用都会被转发到主副本。因此,除非您想使用辅助副本(它们只有读取权限),否则您不必提供replicaId。如果您确实想要访问辅助副本,则必须使用反向代理或 URL 中的 replicaId。
    猜你喜欢
    • 2016-04-22
    • 2016-07-13
    • 2016-01-19
    • 1970-01-01
    • 2016-11-09
    • 1970-01-01
    • 2018-10-16
    • 2021-02-09
    • 1970-01-01
    相关资源
    最近更新 更多