【问题标题】:Service Fabric:How to Call Service with ServiceFabricIntegrationOptions.UseUniqueServiceUrl?Service Fabric:如何使用 ServiceFabricIntegrationOptions.UseUniqueServiceUrl 调用服务?
【发布时间】:2019-06-19 18:11:51
【问题描述】:

我正在尝试通过在有状态服务上使用以下配置使无状态 ASP.NET Core 服务与有状态 ASP.NET Core 服务通信:

protected override IEnumerable<ServiceReplicaListener> CreateServiceReplicaListeners()
        {
            return new ServiceReplicaListener[]
            {
                new ServiceReplicaListener(serviceContext =>
                    new KestrelCommunicationListener(serviceContext, (url, listener) =>
                    {
                        ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting Kestrel on {url}");

                        return new WebHostBuilder()
                            .UseKestrel()
                            .ConfigureServices(
                                services => services
                                    .AddSingleton<StatefulServiceContext>(serviceContext)
                                    .AddSingleton<IReliableStateManager>(this.StateManager))
                            .UseContentRoot(Directory.GetCurrentDirectory())
                            .UseStartup<Startup>()
                            .UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.UseUniqueServiceUrl)
                            .UseUrls(url)
                            .Build();
                    }))
            };
        }

我知道如何通过使用以下 URL http://localhost:19081/App/Service/api/events?PartitionKey=0&amp;PartitionKind=Int64Range 来使用反向代理,但我对如何在没有反向代理的情况下使用它感到困惑。如果我尝试使用fabric:/App/Service 如何指定分区?此外,我似乎无法对 HttpClient 类执行此操作,因为它只接受 HTTP 或 HTTPS。

【问题讨论】:

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


    【解决方案1】:

    通常使用 Service Fabric Remoting 与集群内的有状态服务通信。 它使用一个代理对象来处理连接、解析和重试。

    Here's a sample project 演示了无状态服务与有状态服务的对话。 它使用ServicePartitionKey选择正确的分区,TargetReplicaSelector选择一个副本;主要用于读/写或次要用于读取访问。

    long partitionKey = PartitionAddressFromWord(word);
    var proxy = _dictionaryServiceProxyFactory.CreateServiceProxy<IDictionaryService>(DictionaryServiceUri, new ServicePartitionKey(partitionKey), TargetReplicaSelector.PrimaryReplica, DictionaryServiceListenerSettings.RemotingListenerName);
    return proxy.Lookup(word);
    

    请注意,确定要使用的分区键的代码是您需要根据对服务数据进行分区的方式创建的。 更多信息here.

    【讨论】:

    • 我了解删除方面,但删除并不是所有服务的标准通信。如果我有一个容器调用有状态服务,我会怎么做?这就是我想做基于 http 的通信的原因
    • 如果容器可以使用 SDK,它也可以使用远程处理。如果要使用 HTTP,可以使用内置的 DNS 服务。 docs.microsoft.com/en-us/azure/service-fabric/…
    猜你喜欢
    • 2018-08-08
    • 2018-09-15
    • 2017-09-02
    • 2019-02-21
    • 2017-06-19
    • 2016-12-13
    • 2016-08-27
    • 2019-07-24
    • 2015-12-24
    相关资源
    最近更新 更多