在 GCP PubSub 中收到任何响应之前重试总超时时间已超过

Mah*_*ade 5 publish-subscribe node.js google-cloud-pubsub

我正在尝试使用模块推送到节点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;
Run Code Online (Sandbox Code Playgroud)

但出现这个错误

 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
   } 
Run Code Online (Sandbox Code Playgroud)

Mah*_*ade 2

我通过在 package.json 中添加“google-gax”:“1.6.2”解决了这个问题

@grpc/grpc-js@0.6.x 存在内存泄漏问题。google-gax 需要 grpc,而 pubsub、cloud-task 和其他 google 模块又需要 grpc。

这里这里有一些相关问题