I have to make new project using micro service architecture. As I done my research, I found that Azure service bus is one of best practices for micro services. I understand how messages are sent to the bus and how to subscribe a message receiver, but what I couldn't figure out is how from MVC app to request data from service with parameters and receive result without locking all messages in queue while checking if message is for current request?
I have tried googling a lot but I couldn't find solution.
I am trying to avoid API http request/response between services, but for now I don't see alternative.
CodePudding user response:
I couldn't figure out is how from MVC app to request data from service with parameters and receive result without locking all messages in queue while checking if message is for current request?
It sounds like you've got a mismatch. A consumer of messages (receiver/subscriber) does not lock all messages in the queue. Rather, only the messages that it receives. But that's not the mismatch.
When working with a web application, you're handling requests that require a synchronous response. Messaging is asynchronous. There are ways to bridge the gap with technologies like WebSockets and SignalR. A request should not wait for a message processing to be completed as the time is not guaranteed, and the response would time out. Not to mention that messaging is commonly used to de-couple sub-systems.
I am trying to avoid API http request/response between services, but for now I don't see alternative.
If your services are backend services, asynchronous communication via messaging is fine. If your starting point in the chain of invocation is a web application with a user on the other end waiting for a response, consider returning a response asynchronously with something like SignalR, blocking the client side UI until the response arrives or timing out.