microdot | Microdot : An open source .NET microservices framework | Microservice library
kandi X-RAY | microdot Summary
Support
Quality
Security
License
Reuse
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample Here
microdot Key Features
microdot Examples and Code Snippets
Trending Discussions on microdot
Trending Discussions on microdot
QUESTION
I am thinking of building an application using a Service Oriented Architecture (SOA).
This architecture is not as complex and messy as a microservices solution (I think), but I am facing similar design problems. Imagine I have services of type ServiceA that send work to services of type ServiceB. I guess, if I use a queue, then load balancing will not be a problem (since consumers will take what they can handle from the queue). But queues tend to generate some bad asynchrony in the code that requires extra effort to fix. So, I was more inclined to use HTTP calls between services, using the efficient and amazing async/await
feature of C#. But this generates issues on sharing the workload and detecting services that are saturated or dead.
So my questions are:
- Is there a queue that supports some sort of
async/await
feature and that functions like an HTTP call that returns the result where you need it and not in some callback where you cannot continue your original execution flow? - How do I load-balance the traffic between services and detect nodes that are not suitable for new assignments when using HTTP? I mean, I can probably design something by myself from scratch, but there ought to be some standard way or library or framework to do that by now. The best I found online was this, but it is built for microservices, so I am not sure if I can use it without problems or overkills.
Update: I have now discovered this question, that also asks for awaitable queues: awaitable Task based queue ...and also discovered Kubernetes, Marathon, and the like.
ANSWER
Answered 2018-Nov-04 at 20:38Regarding your first question, NServiceBus, which is a commercial framework for .NET that abstracts message transports and adds many features on top of them, has the exact feature that you are looking for. They actually call it "callbacks" and the usage is as follows:
Assuming you have a Message to send to a backend service and a Response that you expect back, you would do, in ServiceA:
var message = new Message();
var response = await endpoint.Request(message);
log.Info($"Callback received with response:{response.Result}");
Where endpoint is an NServiceBus artifact that allows you to send messages and receive messages.
What this simple syntax will do is put Message in a queue and wait (asynchronously) until the message has been handled by a backend service and it has replied to it. The response is a message of type Response in a queue.
In ServiceB, you would do:
public class Handler : IHandleMessages
{
public Task Handle(Message message, IMessageHandlerContext context)
{
var responseMessage = new ResponseMessage
{
Result = "TheResult"
};
return context.Reply(responseMessage);
}
}
This allows you to have multiple ServiceA nodes sending messages to multiple ServiceB nodes (competing consumers on a single queueu). NServiceBus takes care of routing the response to the right ServerA for every given message.
Note that this has the disadvantage that if ServerA goes down while waiting a response, you'll never receive the response. For this reason, this pattern is not recommended for most scenarios.
Regarding your question number 2, I would say a load balancer would do the job. For more complex scenarios, you could look at Service Fabric.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install microdot
Create your service host that will run your service
Define your public-facing service interface. Methods on that interface can be called from outside.
Define your stateless-worker service grain and interface that implement the public-facing interface.
Define any other grains you need to perform the required processing.
Run your service (F5)
Support
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesExplore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits
Save this library and start creating your kit
Share this Page