node.js – Problem: conflict mqtt clientId when running multiple pods

When 1 of my 6 pods connected to the mqtt in AWS IoT Core, another pods will also try to connect with the same clientId in the .env config of the node server. This will lead to the disconnection and reconnection to the new pod. This event happens continously, and the topic “$aws/events/presence/connected/#” received multiples messages in 1 second. This make the mqtt client unstable.

connection code

I tried to lock the connection of the mqtt client on just 1 pod by storing the status of the client connection in the database. status record in db However, this leads to another problem that when I call an API to publish 1 topic using the mqtt client, the API can not know which pod which hás the mqtt client connected.

Please help me!

Read more here: Source link