I am using microservice architecture. Let say there are two services i.e A and B. I am trying to request from service A to service B which fetch some data from database and give that data as response to service A. But when there is huge amount of data then service B is unable to send in response but it prints on console. I tried many things but none were worked. Please help me on this.
SERVICE A
function makePostRequest(url, data, cb) {
let postContents = {
headers: {
'content-type': 'application/json'
},
url: url,
form: data,
timeout: 1200000
}
console.log('POST ==> ', postContents)
request.post(postContents, function(err, response, body) {
console.log(err)
if (err) {
return cb({
code: httpStatus.serverError,
message: err
})
}
else if (response.statusCode != 200) {
return cb({
code: response.statusCode,
message: body
})
}
else {
console.log(body, 'bodybodybodyPOST')
try {
var data = JSON.parse(body);
if (data && typeof data == 'object')
return cb(null, data)
else
return cb({
code: httpStatus.serverError,
message: 'invalid response'
})
}
catch(Ex) {
console.log(Ex)
return cb({
code: httpStatus.serverError,
message: Ex
})
}
}
})
}
exports.myapi = (req, res) => {
makePostRequest(SERVICE-B-URL, POST-DATA, (e, d) => {
if (e) res.status(500).json({msg: 'please try later'})
else res.status(200).json({msg: 'data fetched', result: d})
})
}
SERVICE B
console.log(result)
console.log('sending response ...', resTotal)
res.status(200).json({
total: resTotal,
result: result,
condition: req.query
});
[ RowDataPacket { f_stamp: 2019-05-25T05:17:48.000Z, f_player_id: 33370333, amount: -0.5, f_param_notes: null, f_money_type: 'R', f_type: 84 }, RowDataPacket { f_stamp: 2019-05-25T05:14:44.000Z, f_player_id: 31946955, amount: 30.9, f_param_notes: null, f_money_type: 'R', f_type: 70 }, RowDataPacket { f_stamp: 2019-05-25T05:14:41.000Z, f_player_id: 31035703, amount: 258, f_param_notes: null, f_money_type: 'R', f_type: 70 }, ... 163783 more items ] sending response .... 163883