Google Pub/Sub每约5条消息仅发送一个订阅 [英] Google Pub/Sub sending to only one subscription every ~5 messages

查看:161
本文介绍了Google Pub/Sub每约5条消息仅发送一个订阅的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使3个客户端连接到一个订阅,以及1个发布者.在图像2中,订阅位于终端上,并且看不到一个订阅,因为它托管在DigitalOcean Droplet上.似乎每5条消息,它切换哪个订户实际接收到该消息,这不应该发生.我也改变了速度,它总是大约5条消息.

I've made 3 clients connected to a subscription, and one publisher. In the image 2 of the subscriptions are on the terminal, and one subscription is not seen as it is hosted on a DigitalOcean Droplet. It seems every 5 messages, it switches which subscriber actually receives the message, which should not happen. I've also varied the speed and it's always about 5 messages.

以下是所有客户端上用于订阅的代码:

Here is the code used on all clients for subscriptions:

sub.on("message", (msg) => {
  console.log(`Message:1 ${msg.data.toString("utf-8")}`)
  msg.ack()
})

这是发布代码:

console.log("send")
topic.publish(Buffer.from("hey"), {
        channelId: "641273551806267403"
    })

推荐答案

在Cloud Pub/Sub中,订阅是一个逻辑实体,它希望将所有发布到与该订阅相关联的主题的消息.订户是代表订户接收消息的客户端.当有多个订户接收单个订户的消息时,则每个订户都将接收消息的子集.这是负载平衡的情况,其中一个使用多个订户来大规模处理消息.如果需要支持更多消息,则只需打开更多订阅者即可接收来自同一订阅的消息.

In Cloud Pub/Sub, a subscription is a logical entity that wants all messages published to the topic with which the subscription is associated. A subscriber is a client that receives messages on behalf of a subscription. When there are multiple subscribers receiving messages for a single subscription, then each subscriber receives a subset of the messages. This is the load balancing case, where one uses multiple subscribers to process messages at scale; if more messages need to be supported, one just turns up more subscribers to receive messages from the same subscription.

当一个主题有多个订阅时,则必须将每个消息发送给代表每个订阅接收消息的订阅者.这是扇出用例.

When a topic has multiple subscriptions, then every message has to be sent to a subscriber receiving messages on behalf of each subscription. This is the fan out use case.

这里是一张试图使其更清晰的图形.左侧是负载平衡,右侧是扇出:

Here is a graphic that tries to make it a little clearer. The left side is load balancing, the right side is fan out:

这篇关于Google Pub/Sub每约5条消息仅发送一个订阅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆