Subject: Issue with Mismatched Topic and QoS in SUBACK Response

I am encountering an issue while using MQTT over WebSockets. Specifically, when I attempt to subscribe a message using a topic, the “granted QoS” field in the SUBACK response is always empty. The issue arises in the following method:

func didReceive(_ reader: CocoaMQTTReader, suback: FrameSubAck)

The failure occurs at this line:

swift

guard topicsAndQos.count == suback.grantedQos.count else {
    printWarning("UNEXPECTED SUBACK Received: \(suback)")
    return
}

The error message indicates a mismatch between the topic count and the granted QoS count, which results in the following:

UNEXPECTED SUBACK Received: Mismatched counts between topics and granted QoS

Here’s the relevant code for connection, publish, and subscribe:

if mqttVersion == "3.1.1" {
    let clientID = "CocoaMQTT-\(animal!)-" + String(ProcessInfo().processIdentifier)
    let websocket = CocoaMQTTWebSocket(uri: "/mqtt")
    mqtt = CocoaMQTT(clientID: clientID, host: defaultHost, port: 8443, socket: websocket)
    
    let username = "solace-cloud-client"
    mqtt!.username = username
    mqtt!.password = "oc1h2uejbmurk5r7fjv296v07a"
    mqtt!.keepAlive = 120
    mqtt!.delegate = self
    mqtt!.enableSSL = true
    mqtt!.autoReconnect = true
    mqtt!.autoReconnectTimeInterval = 1
    mqtt!.cleanSession = true
}

mqtt.subscribe("topic1", qos: .qos2)
mqtt.publish("topic1", withString: "broker", qos: .qos2)

Could you please assist with identifying the root cause of the mismatch and how to resolve the issue?

Steps to Reproduce:

  1. Establish connection using the above configuration.
  2. Subscribe to the topic “topic1” with QoS 2.
  3. Publish a message to the topic “topic1” with QoS 2.
  4. Receive SUBACK response where granted QoS is empty.

Looking forward to your assistance.

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:.

I don’t have specific information about MQTT over WebSockets SUBACK responses in the Solace documentation. You might find what you’re looking for in the following sources: