我正在尝试使用 Node js 推送到 PubSub 主题@google-cloud/pubsub
模块
这是 JavaScript 代码
const { pubsub } = require('@google-cloud/pubsub');
class MyPubSub {
constructor(container) {
this.publisherUser = pubsub.topic(
this.config.pubSubToBigQueryTopicName, {
batching: {
"maxMessages": 1
}
});
}
publishToPubSub(data) {
let MAX_RETRIES = 3;
return new Promise(async (resolve, reject) => {
if (!data) {
return reject(`Invalid param ${data}`);
}
const dataBuffer = Buffer.from(JSON.stringify(data));
let err, id, cx = 0;
do {
[err, id] = await this.utility.invoker(this.publisherUser.publish(dataBuffer));
cx++;
} while (err && cx <= MAX_RETRIES);
if (err) {
return reject(err);
}
return resolve(id);
});
}
}
module.exports = MyPubSub;
但出现这个错误
error: {
"stack":"Error: Retry total timeout exceeded before any response was received\n
at repeat (/my-service/node_modules/@google-cloud/pubsub/node_modules/google-gax/build/src/normalCalls/retries.js: 80: 31)\n
at Timeout.setTimeout
[as _onTimeout] (/my-service/node_modules/@google-cloud/pubsub/node_modules/google-gax/build/src/normalCalls/retries.js: 113: 25)\n
at ontimeout (timers.js: 498: 11)\n
at tryOnTimeout (timers.js: 323: 5)\n
at Timer.listOnTimeout (timers.js: 290: 5)",
"message":"Retry total timeout exceeded before any response was received",
"code":4
}
我通过在 package.json 中添加“google-gax”:“1.6.2”解决了这个问题
@grpc/[电子邮件受保护] /cdn-cgi/l/email-protection有内存泄漏问题。 google-gax 需要 grpc,而 pubsub、cloud-task 和其他 google 模块又需要 grpc。
以下是一些相关问题here https://github.com/googleapis/nodejs-firestore/issues/768 and here https://github.com/googleapis/nodejs-bigquery/issues/547
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)