如何解决带有 proto loader 问题的 GRPC 连接设置
我是 grpc 的新手,我正在使用 dynamo db,下面是我的代码。我在使用 dynamodb 获取 grpc 调用时遇到问题,为了从数据库中获取结果,这将显示来自 db 的空响应,但是当我从邮递员应用相同的 api 时,这将正常工作,我已附上下面的两个响应>
file name grpc.ts ==>
server.addService(walletProto.WalletService.service,{
GetWalletById: async (
call: ServerUnaryCall<any>,callback: sendUnaryData<any>
) => {
console.log('grpc request ===>',call.request);
const userId = call.request.userId;
let walletInfo = await walletService.getWallet({ userId });
console.log('grpc response ===>',walletInfo);
if (!walletInfo.error) {
const { walletBalance,balanceOnHold,currency } = walletInfo.data;
walletInfo.data = { walletBalance,currency };
callback(null,walletInfo);
} else {
callback(null,walletInfo);
}
}
});
wallet service file===>
getWallet = async ({
userId,}: Interfaces.GetWalletType): Promise<Interfaces.PromiseResponse> => {
try {
console.log('service request ===>',userId);
if (!userId) throw { message: 'User Id required' };
let UserWallet;
// Finding user wallet from database
const walletData = await walletModel
.scan('userId')
.contains(userId)
.exec();
console.log('wallet data DB===>',walletData);
// Checking user wallet on database
// Sending success response in all validation success
return {
error: false,message: MESSAGES.GET_BALANCE.success,status: RESPONSES.SUCCESS,data: walletData,};
} catch (error) {
// Sending error response if any validation Failed
return {
error: true,status: error.status ? error.status : RESPONSES.BADREQUEST,message: error.message,};
}
};
When I run this same apis with postman,this will show me the result from database with particular userId,but no result found when I call this apis from grpc. I attached both the response from postman and grpc.
response from postman===>
{
"error": false,"message": "Success","data": {
"currency": "INR","updatedAt": "2021-07-26T18:49:46.712Z","userId": "d192a5a8-df73-496e-845d-8e97071093b5","walletBalance": 138308,"createdAt": "2021-07-26T08:11:00.378Z","balanceOnHold": 0,"id": "5b2baf8f-67aa-4426-9d59-5ad057ac2a0b"
}
}
grpc response ===>
{
error: false,message: 'Success',status: 200,data: Document {
createdAt: 2021-07-26T15:07:49.537Z,balanceOnHold: 0,walletBalance: 0,currency: 'INR',id: 'c2daf3cc-3d0f-49ab-84b9-7fbbd914b30f',userId: 'd192a5a8-df73-496e-845d-8e97071093b5',updatedAt: 2021-07-26T15:07:49.537Z
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。