Reputation: 572
Using Micro Services approach, I have Service A with 3 instances (A1, A2, A3) that can communicate with Service B which has (B1, B2, B3) instances via AMQP Message based Async communication. Example, by Azure Service Bus queues.
Part of Service A's action implementation, I have 5 Steps to be taken care and 2nd step of the 5 is to reach out to Service B to get some info and proceed further.
When I have a multi receiver approach, how does A2 instance of Service A can handle response from Service B, while actual request was made by A1 instance.
I would like to know how these kind of scenarios handled in multi sender + multi receiver approach in micro services.
Upvotes: 0
Views: 71
Reputation: 1021
In multi node architecture where a distributed queue is being used the general approach is to have locking mechanism. Consider you have an object/request to process which is initially put into the queue. Any of the instances can pick that for processing. Your logic should be like:
In this case there will be no issue if any instance picks the response in the second step you mentioned.
Another approach, along with locking goes like this:
Of course as pointed by @Constantin there should be a link to map the response from B to the original object. Consistent state is another thing you should care about when an object can be handled by multiple instances. There shouldn't be any information which resides in a particular instance's memory.
Upvotes: 1
Reputation: 17683
In order to be posibile that the response from any of the service B instances to be handled by any of the service A instances then the response from B must contain all the information necessary to identify the request from A and resume the process, i.e. an Entity ID, Processs ID or something that most probable is opaque to B.
Also, this means that A1 (or whatever instance sends the request message to B) should not block or wait for the response from B.
Upvotes: 1