Google Pub/Sub sending to only one subscription every ~5 messages

无人久伴 提交于 2020-01-06 06:01:11

问题


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()
})

And here is the code for publishing:

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


回答1:


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:



来源:https://stackoverflow.com/questions/58734968/google-pub-sub-sending-to-only-one-subscription-every-5-messages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!