简体   繁体   English

在ServiceStack多层体系结构中使用哪种通信协议

[英]Which communication protocol to use in a ServiceStack multi-tier architecture

We're planning our system to have a set of publicly accessible services which call into a set of internal services, all implemented using ServiceStack. 我们正在计划系统具有一组可公开访问的服务,这些服务可调用一组内部服务,所有服务均使用ServiceStack实施。

My question is, what is the best method (in terms of performance, stability and code maintanability) for this cross-service communication? 我的问题是,这种跨服务通信的最佳方法(在性能,稳定性和代码可维护性方面)是什么?

Eg should my public services call the internal services using a ServiceStack client or use the Rabbit / Redis messaging system? 例如,我的公共服务应该使用ServiceStack客户端还是使用Rabbit / Redis消息传递系统来调用内部服务? And if the latter, can I call two or more internal services asynchronously and await for the response from both? 如果是后者,我可以异步调用两个或多个内部服务并等待两者的响应吗?

For one-way communications Messaging offers a lot of benefits where if installing a Rabbit MQ Broker is an option, Rabbit MQ provides the more industrial strength option. 对于单向通信,如果选择安装Rabbit MQ代理Rabbit MQ提供了更多的行业优势 ,则消息传递具有很多好处

For request/reply services where requests are transient and both endpoints are required to be up, the typed C# Service Clients allow for more direct/debuggable point-to-point communications with less moving parts. 对于请求/响应服务,其中请求是瞬态的,并且要求两个端点都正常运行,类型的C#服务客户端允许使用更少的活动部件进行更多的直接/可调试的点对点通信。

Using the clients async API's let you easily make multiple calls in parallel, eg: 使用客户端异步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; 

The above code continues after Request1 is completed, you can also use Task.WhenAny() to process which ever request was completed first. 以上代码在Request1完成后继续,您也可以使用Task.WhenAny()处理哪个请求先完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM