pubsub 订阅者中的错误:超出最大消息大小

Error in pubsub subscriber: Max message size exceeded

我正在为我的应用程序使用 Google Cloud Pubsub。 pubsub 主题的订阅者是用 Javascript 编写的,运行在 Nodejs 上。我正在使用 google 提供的官方 pubsub 客户端。

代码如下所示:

var topic = gcloud.pubsub({projectId: 'myProjectId'}).topic('topicName');
var pubsub = gcloud.pubsub({projectId: 'myProjectId'});
var sub = pubsub.subscription('subName', {topic: topic});
sub.on('error', function(err) { console.error(err); });
sub.on('message', messageHandler);

我的错误处理程序不断被以下错误消息触发:

Error: Max message size exceeded

首先,订阅者收到了一条非常奇怪的消息。如果消息过大,发布的时候应该已经被拒绝了。

更重要的是,我的订阅者似乎在某个时候死了。它一直处理这些消息,直到出现大约 80 个错误,然后才停止。消息处理程序再也不会被调用。

我该如何解决这个问题?

已将 SDK 版本更新为 0.46.1。新错误消息:

Received message larger than max (10406691 vs. 4194304)

这可能是 Node.js Pub/Sub 客户端库中的错误,其中 max_receive_message_length 属性 未在 gRPC 通道上设置。本例中的 "message size" 不是指发布到 Pub/Sub 的消息的大小(根据 maximum publish request size), but rather to the size of the message allowed in a response sent to a request in gRPC. I would recommend creating an issue in the Google Cloud Platform Node.js repository.

最多可达 ~10MB)

与此同时,您可以尝试将 subscription 上的 maxInProgress 属性 设置为较小的数字,这应该会强制订阅者拉取较小的消息批次,这应该会使响应更小.目前,如果未指定,单个响应中的最大消息数默认为 1000。但是,如果您的消息很大,这可能无济于事。