Can MQTT iOS client subscribe to the queue?

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

Hi there, I’m Solly AI, I generate responses to your questions using the power of the Solace Agent Mesh:

Please remember that AI technology can make mistakes so ensure that you read our Disclaimer.

AI Generated responses are a work in progress, your help in evaluating my response would be awesome! If my response makes sense, please mark it as a solution or give a :+1:. If my response doesn’t make sense for your topic, please react to it with a :shaking_face:.

Let me analyze the information about MQTT queue-based message consumption in iOS.

The documentation indicates that while MQTT doesn’t natively support direct queue consumption, Solace implements queue functionality under the hood for MQTT connections with specific configurations:

  1. For persistent message consumption with MQTT v5:
  • Set Clean Session to false
  • Use the same client ID consistently
  • Use QoS1 for subscriptions
  • Configure session expiry interval in connect properties
  1. For WebSocket connections:
  • Port 8443 is used for MQTT over WebSocket Secure (WSS)
  • Port 8883 is used for MQTT over SSL/TLS

The code you shared needs some adjustments to enable persistent message consumption:

  1. Set cleanSession to false
  2. Configure a non-zero sessionExpiryInterval
  3. Use QoS1 for subscriptions

MQTT v5 is recommended over MQTT 3.1.1 for better features and interoperability with Solace event brokers.

Here are relevant sources for more information:

Hi @Srikanth_bethi,
As @amackenzie said in the other thread the MQTT5 specification does not include queues and b/c of that the MQTT libraries won’t allow you to explicitly connect to a queue. But Solace’s implementation of QoS uses queues under the covers.

Please refer to this thread for a bit more info: Queue-Based Message Consumption Using CocoaMQTT in Solace in iOS swift - #6 by amackenzie

Hi @marc and @amackenzie ,
The links provided do not offer sufficient information to help me achieve my goal of developing the iOS application. Could you please address the queries below and provide your valuable insights and suggestions?

Task :
I am developing a frontend iOS application that will interact with a Solace messaging system to both publish events to a specified topic and consume events from a queue.

Questions:

  1. Does Solace support message consumption from a queue?
  2. Can the same functionality be achieved using an MQTT library? If MQTT is not suitable, could you suggest alternative approaches for iOS mobile application development to achieve this functionality?

MQTT is suitable, yes.
Connect a consumer with QoS1 and that’s the MQTT equivalent of a queue.

Hi @amackenzie ,
Thank you so much for quick response.

I’m working on iOS front-end application development. I have successfully published messages with QoS1 and can view the “Try Me” dashboard with messages stored in persistent mode. I sent 20 messages, but now I’m having trouble consuming all the persistent 20 messages via topics. I am unable to do so. Could you please provide suggestions, sample code, or any relevant iOS documentation? I would really appreciate your help.

Hi @amackenzie @marc ,
Any update on above my request?

Hi @amackenzie @marc
We are seeking guidance on how the functionality works in the ‘Try Me’ section, and would like to implement the same functionality for the iOS front-end. Could you please provide the steps or code to achieve this on the iOS side?

Hi @Srikanth_bethi,
The Try-Me tool inside of PS+ Manager uses our javascript SMF API w/ the broker’s web messaging port. Another example of this would be the CodePens in section 3 on this page: https://solace.com/products/event-broker/software/getting-started. If you click on the “Edit in CodePen” button at the top right of each of them you’ll be able to see the code. Hope that helps!

@amackenzie any other suggestions here?

Hi @marc
Could you please provide guidance on how to retrieve all persistent messages from a topic/queue using the MQTT framework in an iOS front-end application?

I’m working on iOS front-end application development. I have successfully published messages with QoS1 with messages stored in persistent mode. I sent 20 messages, but now I’m having trouble consuming all the persistent 20 messages via topics. I am unable to do so. Could you please provide suggestions, sample code, or any relevant iOS documentation? I would really appreciate your help.

Providing iOS code with you, Could you please verify and provide corrections for my requirement fulfill.
code:
let clientID = “CocoaMQTT-(“sample”)-” + String(ProcessInfo().processIdentifier)
let websocket = CocoaMQTTWebSocket(uri: “/mqtt”)
websocket.enableSSL = true
mqtt = CocoaMQTT(clientID: mqttClientID, host: mqttHost, port: mqttPort, socket: websocket)
mqtt!.username = “solace-cloud-client”
mqtt!.password = “oc1h2uejbmurk5r7fjv296v07a”
mqtt!.autoReconnect = true
mqtt!.keepAlive = 60
mqtt!.enableSSL = true
mqtt!.delegate = self
mqtt!.cleanSession = false
mqtt!.logLevel = .debug

connection : let connect = mqtt!.connect()
To publish message : mqtt!.publish(topic, withString: message, qos: .qos1, retained: false)
To subscribe messages : mqtt.subscribe(topic, qos: .qos1)

@marc @amackenzie : any updates on above my requirement?