【问题标题】:Service Fabric Remoting to WebApiService Fabric 远程处理到 WebApi
【发布时间】:2018-08-17 08:59:57
【问题描述】:

我们正在运行一些无状态可靠服务,并且在使用反向代理 (http://localhost:19081/{app}/{svc}/bleh) 进行服务到服务通信时遇到性能问题。在不深入细节的情况下,我们正在研究使用远程处理,如下所述:https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-reliable-services-communication-remoting

但是,我很难弄清楚如何在服务类型类中公开 API 方法,因为它们目前存在于我们的控制器中。控制器通过依赖注入获取所需的存储库实例等...,所以我正在研究如何在没有某种冗余实例或循环依赖的情况下完成此任务。

我坐在这里盯着“PersonService.cs”上的这个:

internal sealed class PersonService: StatelessService, IPersonService
{
        public PersonService(StatelessServiceContext context)
            : base(context)
        { }

        ...
        public PersonResponse GetPersonFromDb()
        {
          //lost here :(
        }

我的控制器工作正常,有:

public PersonController(IPersonRepository personRepository)
{
  _personRepository = personRepository;
}
   ...
public IActionResult GetPerson()
{
    var personResponse = _dbRepository.GetPerson();
    return new ObjectResult(personResponse);
}

D:

【问题讨论】:

    标签: remoting stateless azure-service-fabric


    【解决方案1】:

    你不能像这样将存储库传递给你的服务吗?

    public PersonService(StatelessServiceContext context, IPersonRepository personRepository)
                : base(context)
    {
       _personRepository = personRepository;
    }
    
    public PersonResponse GetPersonFromDb()
    {
        var personResponse = _personRepository.GetPerson();
        return personResponse;
    }
    

    【讨论】:

    • 我想就是这么简单。然后我还需要从 MVC 控制器引用服务中的方法。
    • 仅供参考,我们最终坚持使用反向代理进行 ASF 内部通信。将 ServicePointManager.DefaultConnectionLimit 的 2 调整为 100 会有所帮助。
    • 我后来意识到,如果我正确地构建了这个,我就不会遇到这个问题。 MS 示例项目对我帮助很大:github.com/Azure-Samples/service-fabric-dotnet-getting-started
    猜你喜欢
    • 2017-07-26
    • 2017-09-18
    • 2021-02-15
    • 2018-03-26
    • 2018-12-06
    • 2017-09-17
    • 1970-01-01
    • 1970-01-01
    • 2019-04-05
    相关资源
    最近更新 更多