Multi instance backend subscribing to MQTT topic

Hi, I am wondering about the best way to handle the case where my backend is subscribing to MQTT topics in NFR cloud, when I am running multiple instances of it, for example in Kubernetes.

The requirement is that one of the instances should get one message, not all - in a load balanced fashion.

I have read about shared subscriptions and tried to use it. Seems to be working, however I am facing an issue where all of my instances keeps disconnecting and reconnecting. I suspect this is because the MQTT broker only allows one connection per client id, and I am using the same for all my instances (btw I am using a device account to subscribe to the topics from my backend).

My initial thoughts for a solution is:

  1. Some form of leader election mechanism, to give one of my instances a "leader" role, hence subscribing to the topics and the other instances are not (works but complicated)
  2. Generating as many device accounts as I plan to have replicas and use different device account per replica (I don't particularly like this because I don't want to create another account when scaling up, and the logic for grabbing an account feels non trivial)

Any other thoughts for a solution, that might be more straight forward?

Best regards,

Rasmus

Parents Reply Children
  • Yes, we have thought about self hosting our own MQTT broker. However we wanted to explore a managed solution first. FOTA etc is supported out of the box for most managed solutions AFAIK.

    Is it possible to provide answers to my questions? AWS IoT (which NRF cloud is based on AFAIK) does not have a limitation on how many "things" can be created (which I guess is the account device in NRF cloud). So another solution would be to use our own AWS IoT infra, bypassing NRF cloud, right?

Related