【问题标题】:Service Fabric, Remoting V2 to Stateful Service not workingService Fabric,将 V2 远程处理为有状态服务不起作用
【发布时间】:2018-05-07 00:25:52
【问题描述】:

我无法让这个工作,我用谷歌搜索,可能找到了关于如何做到这一点的每一页,全部两个!

基本上,我只是想让 SF Remoting V2 从无状态的 .NET Core 2 MVC 应用程序工作到有状态的服务。

这是我所做的:

Controller 中的客户端代码:(尽可能简化):

public class ValuesController : Controller
{

    [HttpGet]
    public async Task<IEnumerable<string>> Get()
    {

         // Provide certificate details.
        var serviceProxyFactory = new ServiceProxyFactory((c) => new FabricTransportServiceRemotingClientFactory());

        var proxy = serviceProxyFactory.CreateServiceProxy<ICallMe>(new Uri("fabric:/SFExperiment/Stateful1"));

        var value3 = await proxy.GetGreeeting("Bob");

        return new[] { "value1", "value2", value3 };
    }

服务代码接口:

using System.Threading.Tasks;
using Microsoft.ServiceFabric.Services.Remoting;
using Microsoft.ServiceFabric.Services.Remoting.FabricTransport;


[assembly: FabricTransportServiceRemotingProvider(RemotingListener = 
RemotingListener.V2Listener, RemotingClient = RemotingClient.V2Client)]

namespace Stateful1.Abstractions
{

 public interface ICallMe : IService
 {
     Task<string> GetGreeeting(string name);
 }
}

服务代码:

    Public sealed class Stateful1 : StatefulService, ICallMe
{
    public Stateful1(StatefulServiceContext context)
        : base(context)
    { }

    protected override IEnumerable<ServiceReplicaListener> CreateServiceReplicaListeners()
    {
        return this.CreateServiceRemotingReplicaListeners();
    }

    public Task<string> GetGreeeting(string name)
    {
        return Task.FromResult(@"Congratulations, you have remoting working. :-) ");
    }

我已在下面添加到 ServiceManifest.xml

  <Resources>
<Endpoints>
  <!-- To enable Service remonting for remoting services V2-->
  <Endpoint Name="ServiceEndpointV2" />

  <Endpoint Name="ReplicatorEndpoint" />
</Endpoints>
</Resources>

它不起作用..我得到以下异常:

选择器 {1}

的分区键/ID“{0}”无效

我做错了什么?

【问题讨论】:

    标签: azure-service-fabric service-fabric-stateful service-fabric-stateless


    【解决方案1】:

    在创建服务代理的调用中,您必须指定分区键,因为您要连接到有状态服务。

    long partitionKey = 0L;  //TODO: Determine partition key
    var proxy = serviceProxyFactory.CreateServiceProxy<ICallMe>(new Uri("fabric:/SFExperiment/Stateful1"), new ServicePartitionKey(partitionKey), TargetReplicaSelector.PrimaryReplica);
    

    另外,请确保您重复使用您的服务代理工厂,而不是创建一个新的。 以this 代码为例。

    【讨论】:

      猜你喜欢
      • 2018-03-26
      • 2017-07-26
      • 2020-02-01
      • 1970-01-01
      • 2017-09-17
      • 2016-11-16
      • 2021-02-15
      • 2018-04-09
      • 2019-04-05
      相关资源
      最近更新 更多