grpc连接设置与proto loader问题

e4yzc0pl  于 2021-09-29  发布在  Java
关注(0)|答案(0)|浏览(253)

我是grpc的新手,我使用的是dynamo db,下面是我的代码。我在使用dynamodb获取grpc调用时遇到了问题,为了从数据库获取结果,这将显示来自db的空响应,但是当我应用来自postman的相同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, balanceOnHold, 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
}

}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题