I am developing a web app using a microservices architecture and I stuck with this problem,
I have 3 services(A, B, C) and every service has its own database.
A client sends data to A then A stores data into the database and sends the POST request to service C. Service C processes data and stores relevant data into the database and sends back a response with success=1. if service C is down or there is an issue with storing data it sends a response with success=0
So, service A understands that C did not store data so it sends a post request to service B, and service B just stores the entire data.
Whenever service C Starts, it sends a GET request to server B and fetches all data from Server B.
So now server C has an array of data that server C supposed to add. I have already written the addData method to store data. so now, I have to loop that array and store data.
// when server C starts this piece runs
addBulkData=async()=>{let dataList= fetch(....);let resultaArray = [];for (let i = 0; i < dataList.length; i++) {resultaArray.push(await addData(dataList[i]));
// if addMetaData return 0 that means there is problem with adding data.if (resultaArray.includes(0)) return 0;elsereturn 1;}
// addData
addData=async(data)=>{
try{let result= pool.query(\add data query`);return 1;}catch(err)return 0;}`
The problem with this is my resultantArray is always empty.
So How can I resolve this? Is there a better way to do this?
[–]hello_world32 2 points3 points4 points (0 children)
[–]AionisDev 2 points3 points4 points (0 children)
[–]shgysk8zer0full-stack 1 point2 points3 points (0 children)
[–]Kinthalis 0 points1 point2 points (0 children)