@grpc/grpc-js:^1.3.3 Node.js: v14.17.3
Client.js
client.updateBillingItems(request, function(err, response) {
if (err) {
res.send({error:'Server failed to update billing item'});
}
else {
res.send(response);
}
});backend.js
PCServiceImpl.prototype.updateBillingItems = function updateBillingItems(call, callback) {
var billingitems = call.request.billingitems; //Here the request received ( request: { billingitems: [] } ) is empty although data is passed from the client. Hence the susequent code fails to execute.
console.log('updateBillingItems:', billingitems)
es_query_obj.es_update_billing_items(billingitems)
.then( results => {
console.log('updateBillingItems:', JSON.stringify(results));
callback(null, results);
})
.catch(err => {
console.error("updateBillingItems: Caught ES exception:", err)
callback(err)
});
} 请求:{记账项:[] } ->帐单项必须为如下数组
[{"chargemonth":"2021-12","dateofservice":"2021-12-20","geo":"LA"}]因此,每当updateBillingItems()被client.js调用时,它尝试以数组的形式将更新后的数据发送到后端服务,但是后端服务接收的请求是空的,不确定原因。我的代码也使用proto,请求和响应格式都是按照proto定义的,但是这个调用仍然失败。
发布于 2022-06-06 06:58:07
事实证明,grpc-js json -> proto转换具有奇怪的命名约定。
考虑到以下主要问题:
message SomeMsg{
string some_string_field = 1;
}客户机和服务器impl将需要引用字段w/ camel的情况。
....
console.log(data.someStringField)
...https://stackoverflow.com/questions/70493588
复制相似问题