Can MQTT flutter client subscribe to the queue

I am building a frontend application that should consume events from the solace queue via MQTT. So that when i get online after closing the app for a while, i should receive the events that are persisted in the queue, Possible to get the data? If mqtt is not possible, then let me know what other options.

Hi @Logesh ,

your requirement is:

  • Use MQTT
  • consume data from a queue after app is down for a while
    ?
    This does not work with MQTT protocol.
    In MQTT QoS1 (=Quality-of-Service 1… in Solace terms we name it “guaranteed messaging”), the subscription will be deleted after 60sec of downtime of app.
    If your app re-connects after 45 sec, you see all messages arrived during the downtime.
    If your app re-connects after 70sec, you don’t see messages arrived during the downtime.

I would recommend to use a different protocol for consuming, eg. all protocols from the Solace-protocol-family (for Java, Python, Go, c, ….) or AMQP if you’re in open protocols.
Hope that helps.

Uli

Thanks for the prompt reply.
The requirement is not to use MQTT, it is to use flutter, and connect to the queue to get messages even after reconnecting - as long as the event stays in the queue.
What would be the best practice to use with flutter that helps with scale.

@Logesh You can actually use MQTT to achieve your desired outcome:

  1. When you connect to Solace broker, set MQTT Clean Session to false
  2. Always use the same client ID to connect
  3. Use QoS1 subscription

With the above configuration, the session, client info, queue(auto generated) and data with matching subscription will be persistent in the broker. When the same client reconnect, it will be able to receive all data from the queue.

It worked! Thankyou so so much!

@Logesh and @yangsen :
I am developing a frontend iOS application that needs to consume events from a Solace queue using MQTTv5. Does MQTT v5 support consuming all persistent messages from a queue?

Here’s a bit of the code I’m using. Could you provide any corrections or clarifications?
NOTE: I am using over websocket with port 8443

let websocket = CocoaMQTTWebSocket(uri: "/mqtt")
        mqtt5 = CocoaMQTT5(clientID: mqttClientID, host: mqttHost, port: 8443, socket: websocket)

        let connectProperties = MqttConnectProperties()
        connectProperties.topicAliasMaximum = 0
        connectProperties.sessionExpiryInterval = 0
        connectProperties.receiveMaximum = 100
        connectProperties.maximumPacketSize = 500
        mqtt5!.connectProperties = connectProperties

        mqtt5!.username = "solace-cloud-client"
        mqtt5!.password = "oc1h2uejbmurk5r7fjv296v07a"
        
        mqtt5!.cleanSession = false
        mqtt5!.autoReconnect = false
        mqtt5!.keepAlive = 120
        mqtt5!.enableSSL = true
        mqtt5!.delegate = self
        mqtt5!.logLevel = .debug

@Logesh @yangsen
Your valuable suggestions would be like a lifesaver in this tough moment. I kindly ask for your guidance and support

Sorry for the late reply, was busy with some tasks.
To achieve your purpose, you will need:

  1. cleanSession = false :white_check_mark:
  2. set sessionExpiryInterval = 0 :white_check_mark:
  3. Always use the same MQTT client ID :white_check_mark:
  4. Use QoS =1 subscription

Remember, there is no queue in MQTT, only topics. When you use QoS=1 subscripion, Solace will create a queue internally to persist messages with matching topic subscription. This queue is transparent to client. When the cleanSession is set to false, the broker will persist the MQTT session and queue, so that the same resource will be reused when the client disconnect and connect back, and it won’t lose any message published during its disconnection.

Thank you so much for your valuable suggestions.
@yangsen : In our setup, each client (identified by a unique device name, which we use as the client ID) connects to Solace using MQTT. I’ve observed that for every connected client, a new queue is automatically created in the Solace dashboard. For example, when 500 devices connect, 500 individual queues are created.

Is this the expected behavior when using MQTT with Solace? Or is there a way to avoid creating a separate queue for each client?

This is expected if the client has QoS1 subscription. As the broker need to use the queue to persist messages which match topic subscription of the client. If the client only publish data or only have QoS=0 subscription, there shouldn’t be queue created.
If the client use clean session(Or for MQTTv5, a non-zero sessionExpiryInterval value), the queue and associated session will disappear automatically when it disconnect