Closed Gabones closed 1 month ago
I'm not a flutter user so I'm not sure what -
I have the following issue: every time the package pings the server, the StreamBuilder is triggered. and I receive the last message again in the app...
means but I can tell you how the client works.
The client will not give you the last publish message received again once you have consumed it through its listener so I assume that flutter is somehow caching this. When you say 'pings the server' I assume you are using the keep alive functionality provided by the client, if so then I doubt its the sending of the ping request to the broker that's triggering anything, more like the ping response generated by the broker is doing this.
Each received publish message does have a unique message identifier, you can access it like this -
publishMessage. variableHeader.messageIdentifier
These are allocated by the broker so exact values wont be of use to you also they will be reused over time, however, the message identifier of a received publish message should be different to the last one received in all cases. You could use this to compare your last message with the previous one, if they are the same you can discard the message.
I have managed to implement an app with mqtt_client and connect it to AWS IoT Core. The mqtt connection is coded inside a flutter provider. I'm listening to published messages through a StreamBuilder widget, and everything seems to work fine. However, I have the following issue: every time the package pings the server, the StreamBuilder is triggered, and I receive the last message again in the app. I tried to find a solution for this but didn't manage to. Is there something I can do to prevent this, or is adding a unique ID to my messages the only way?