0
votes

We are using Google PubSub for an IoT project in a multi-tenant system

  • Each device from the same tenant delivers a 'heartbeat' message every minute.
  • Each tenant has its own topic.
  • Each device has its own subscription to the topic.

The problem we are having is: when we un-plug a device for a couple of days, and then re-plug it, it starts to receive hundreds of messages (old heartbeats from the other devices) that make the device slow for a few minutes.

The question is:

What do you think is the correct way to work with this?

  • one topic per device?
  • is there a way to clear the suscription and avoid receiving old messages?

We are open to recommendations.

Thank you!!!

1

1 Answers

1
votes

In Google Cloud Pub/Sub, messages will be retained for subscriptions for 7 days. Therefore, if your device reconnects, it will receive up to 7 days worth of messages.

To skip older messages, one can use seek on a Pub/Sub subscription (currently in alpha) to ack older messages by seeking to a timestamp corresponding to now. The devices could each call this API when they start up before they start to subscribe as a means to clear out the older messages.

Regarding your setup in general, how many tenants and devices do you have? Keep in mind the quotas: a single project can only have 10,000 topics and 10,000 subscriptions.