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

StackOverflow https://stackoverflow.com/questions/23573643

  •  19-07-2023
  •  | 
  •  

سؤال

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.

My question is, what is the best method (in terms of performance, stability and code maintanability) for this cross-service communication?

E.g. should my public services call the internal services using a ServiceStack client or use the Rabbit / Redis messaging system? 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.

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.

Using the clients async API's let you easily make multiple calls in parallel, e.g:

//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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top