MQTT API Reference
MQTT 3.1.1 client library

Check if an MQTT connection has a subscription for a topic filter.

const char * pTopicFilter,
uint16_t topicFilterLength,
IotMqttSubscription_t * const pCurrentSubscription );

This function checks whether an MQTT connection mqttConnection has a subscription callback registered for a topic filter pTopicFilter. If a subscription callback is found, its details are copied into the output parameter pCurrentSubscription. This subscription callback will be invoked for incoming PUBLISH messages on pTopicFilter.

The check for a matching subscription is only performed client-side; therefore, this function should not be relied upon for perfect accuracy. For example, this function may return an incorrect result if the MQTT server crashes and drops subscriptions without informing the client.

Note that an MQTT connection's subscriptions might change between the time this function checks the subscription list and its caller tests the return value. This function certainly should not be used concurrently with any pending SUBSCRIBE or UNSUBSCRIBE operations.

One suitable use of this function is to check which subscriptions were rejected if IotMqtt_SubscribeAsync returns IOT_MQTT_SERVER_REFUSED; that return code only means that at least one subscription was rejected.

[in]mqttConnectionThe MQTT connection to check.
[in]pTopicFilterThe topic filter to check.
[in]topicFilterLengthLength of pTopicFilter.
[out]pCurrentSubscriptionIf a subscription is found, its details are copied here. This output parameter is only valid if this function returns true. Pass NULL to ignore.
true if a subscription was found; false otherwise.
The subscription QoS is not stored by the MQTT library; therefore, pCurrentSubscription->qos will always be set to IOT_MQTT_QOS_0.
struct _mqttConnection * IotMqttConnection_t
Opaque handle of an MQTT connection.
Definition: iot_mqtt_types.h:66
bool IotMqtt_IsSubscribed(IotMqttConnection_t mqttConnection, const char *pTopicFilter, uint16_t topicFilterLength, IotMqttSubscription_t *const pCurrentSubscription)
Check if an MQTT connection has a subscription for a topic filter.
Definition: iot_mqtt_subscription.c:584
Information on an MQTT subscription.
Definition: iot_mqtt_types.h:550