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

  • Hi Rasmus,

    Here is a reply from our nRF Cloud developer, could you provide your team ID and account devices amount you what you need?

    Only 1 account device is allowed now, and the supported REST API endpoints to use are:

    • GetAccountDeviceCertificate
    • RotateAccountDeviceCertificate
    • DeleteAccountDevice

    The mentions in the DevZone ticket about CreateAccountDeviceAndCertificate and related endpoints are deprecated equivalents that should not be used. They do NOT allow creation of more than one account device, just like the  3 bulleted supported endpoints above do not allow more than one.

    We are considering adding feature support to allow creation of multiple account devices, but it's not possible now by the user. But we can create the 2nd, 3rd, etc account devices for them manually and give them the client device IDs and certs, if we have their team ID.

    Best regards,

    Charlie

  • Hi Rasmus,

    I have created 3 more account devices and sent their credentials to your email.

    If they work for you, and you still need more account devices, I can create them, but it is a manual process.

    We will soon be supporting user creation of multiple account devices.

    Regards,

    Lincoln

Related