【问题标题】:Which communication protocol to use in a ServiceStack multi-tier architecture在 ServiceStack 多层架构中使用哪种通信协议
【发布时间】:2014-05-09 20:43:20
【问题描述】:

我们计划让我们的系统拥有一组可公开访问的服务,这些服务调用一组内部服务,所有这些都使用 ServiceStack 实现。

我的问题是,这种跨服务通信的最佳方法是什么(就性能、稳定性和代码可维护性而言)?

例如我的公共服务应该使用 ServiceStack 客户端调用内部服务还是使用 Rabbit / Redis 消息传递系统?如果是后者,我可以异步调用两个或多个内部服务并等待两者的响应吗?

【问题讨论】:

    标签: c# servicestack


    【解决方案1】:

    对于单向通信Messaging offers a lot of benefits,如果安装Rabbit MQ Broker 是一种选择,Rabbit MQ 提供更工业强度的选择。

    对于请求是瞬态的并且要求两个端点都启动的请求/回复服务,键入 C# Service Clients 允许使用更少的移动部件进行更直接/可调试的点对点通信。

    使用客户端异步 API 让您可以轻松地进行多个并行调用,例如:

    //fire off to 2 async requests simultaneously...
    var task1 = client.GetAsync(new Request1 { ... });
    var task2 = client.GetAsync(new Request2 { ... });
    
    //additional processing if any...
    
    //Continue when first response is received
    var response1 = await task1;
    
    //Continue after 2nd response, if it arrived before task1, call returns instantly
    var response2 = await task1; 
    

    上面的代码在Request1完成后继续,你也可以使用Task.WhenAny()来处理哪个请求先完成。

    【讨论】:

      猜你喜欢
      • 2012-07-14
      • 1970-01-01
      • 2011-08-27
      • 2016-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-27
      相关资源
      最近更新 更多