You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds a client for publishing to the custom topics an mqttv5 hub allows through its topic templates (properties.mqttV5Settings.topicGroups[].topicTemplates).
API (inc/azure/iot/mqttv5/az_iot_custom_topic_client.h)
az_iot_mqttv5_custom_topic_client_init() / _deinit(): attaches to a connection, like the other mqttv5 clients. Fails with AZ_IOT_ERR_CONNECTION_PROFILE_MISMATCH on an mqttv3 connection.
az_iot_mqttv5_custom_topic_client_publish(): QoS 0 or 1, optional content type, user properties and message expiry.
The message is sent as given; the client adds no user properties of its own.
Completion reports the PUBACK result: AZ_IOT_ERR_PUBLISH_REFUSED when no template matches, AZ_IOT_ERR_MQTT when the adapter gives no reason.
az_iot_mqttv5_custom_topic_client_format_topic(): replaces {deviceId} with the connection's device id.
The variable is case-sensitive, and any other {/} is rejected, matching the hub's template syntax.
Returns AZ_IOT_ERR_NOT_CONNECTED until connected, because the device id can still change during provisioning.
Local topic validation
Topics the hub would refuse are rejected with AZ_IOT_ERR_INVALID_ARG, and nothing is sent:
+ or # anywhere;
a leading $;
a first level of exactly ih, the hub's reserved namespace;
more than 256 bytes or more than 15 levels (the broker's limits);
malformed UTF-8.
Scope
Publish only. Custom topics cannot be subscribed to in this release.
No retain, response topic or correlation data. Fields can be appended later; zero keeps the current behaviour.
Linux, gcc 12, linux-gcc-debug preset with the az_mqtt adapter on: clean build, no warnings.
ctest: 53 of 59 suites pass, including the new az_iot_tests_mqttv5_custom_topic_client.
Failing: az_iot_conformance_paho_v3, az_iot_conformance_paho_v5, az_iot_conformance_paho_sign_negative, az_iot_conformance_az_mqtt_v3, az_iot_conformance_az_mqtt_v5 and az_iot_reconnect_integration. These are the broker-backed suites; this change does not touch the code they exercise.
paho_v5, az_mqtt_v5 and reconnect_integration fail the same way on unmodified main in the same environment. The other three were not re-run there.
This branch is unreachable with the adapter this sample registers. az_iot_paho_factory_create_v5() routes every MQTT v5 publish failure to AZ_IOT_ERR_MQTT (c/adapters/paho/az_iot_mqtt_paho.c:940-946), so a no-template PUBACK will always fall through to the generic error and the advertised “hub refused” diagnostic is never shown. Either use a v5 adapter that preserves the PUBACK reason, or update Paho to classify response->reasonCode with az_iot_mqtt_puback_result() and keep the sample/README aligned.
Re: unreachable "hub refused" diagnostic in the sample: correct for Paho, which reports every failed MQTT v5 publish as AZ_IOT_ERR_MQTT. Classifying Paho's PUBACK reason code is a separate adapter change. Here the sample and its README now say that with Paho a refusal surfaces as AZ_IOT_ERR_MQTT; the AZ_IOT_ERR_PUBLISH_REFUSED branch stays for adapters that report it (az_mqtt does).
The reason will be displayed to describe this comment to others. Learn more.
Why telemetry? just because it can be reused?
It better be typedef'ed into a specific type name, in case we need to separate things in the future. Push back if you will
The reason will be displayed to describe this comment to others. Learn more.
Agreed, done in 8cdf6cf: publish() now takes its own az_iot_mqttv5_custom_topic_publish_callback (same signature), so it can diverge from telemetry later. The header no longer includes az_iot_message.h.
The reason will be displayed to describe this comment to others. Learn more.
Not a good practice to mix public and static functions like this.
Functions shall be defined in the source code in this order:
static internal function prototype defines
public functions
static internal function implementations.
Add az_iot_mqttv5_custom_topic_client for publishing to the custom topics
an mqttv5 hub's topic templates allow.
- publish(): QoS 0 or 1, content type, user properties, message expiry.
Sent as given; the client adds no user properties.
- format_topic(): replaces {deviceId} with the connection's device id.
Other {...} tokens are rejected, as on the hub.
- Topics the hub would refuse are rejected locally: wildcards, a leading
'$', a first level of "ih", more than 256 bytes or 15 levels, or
malformed UTF-8.
- Publish only: custom topics cannot be subscribed to.
Includes unit tests, the mqttv5/custom_topic_publisher sample and docs.
…ract
- format_topic(): a literal run that cannot fit the output fails with
AZ_IOT_ERR_NOT_ENOUGH_SPACE before it reaches az_span_create().
- init(): document that the client must not already be initialized and
that the connection must outlive it.
- ci-c coverage: expect 53 test suites.
…usals yet
The Paho adapter reports every failed MQTT v5 publish as AZ_IOT_ERR_MQTT,
so with it a topic no template matches does not reach the sample's
AZ_IOT_ERR_PUBLISH_REFUSED branch. Say so in the sample and its README.
- publish() takes az_iot_mqttv5_custom_topic_publish_callback instead of
reusing the telemetry callback type, so the two can diverge.
- custom_topic_client.c: static prototypes, then public functions, then
static implementations.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a client for publishing to the custom topics an mqttv5 hub allows through its topic templates (
properties.mqttV5Settings.topicGroups[].topicTemplates).API (
inc/azure/iot/mqttv5/az_iot_custom_topic_client.h)az_iot_mqttv5_custom_topic_client_init()/_deinit(): attaches to a connection, like the other mqttv5 clients. Fails withAZ_IOT_ERR_CONNECTION_PROFILE_MISMATCHon an mqttv3 connection.az_iot_mqttv5_custom_topic_client_publish(): QoS 0 or 1, optional content type, user properties and message expiry.AZ_IOT_ERR_PUBLISH_REFUSEDwhen no template matches,AZ_IOT_ERR_MQTTwhen the adapter gives no reason.az_iot_mqttv5_custom_topic_client_format_topic(): replaces{deviceId}with the connection's device id.{/}is rejected, matching the hub's template syntax.AZ_IOT_ERR_NOT_CONNECTEDuntil connected, because the device id can still change during provisioning.Local topic validation
Topics the hub would refuse are rejected with
AZ_IOT_ERR_INVALID_ARG, and nothing is sent:+or#anywhere;$;ih, the hub's reserved namespace;Scope
Also
mqttv5_custom_topiclog component.samples/mqttv5/custom_topic_publisher.Validation
linux-gcc-debugpreset with the az_mqtt adapter on: clean build, no warnings.ctest: 53 of 59 suites pass, including the newaz_iot_tests_mqttv5_custom_topic_client.az_iot_conformance_paho_v3,az_iot_conformance_paho_v5,az_iot_conformance_paho_sign_negative,az_iot_conformance_az_mqtt_v3,az_iot_conformance_az_mqtt_v5andaz_iot_reconnect_integration. These are the broker-backed suites; this change does not touch the code they exercise.paho_v5,az_mqtt_v5andreconnect_integrationfail the same way on unmodifiedmainin the same environment. The other three were not re-run there.eng/code-style.sh check(clang-format 18.1.8),check-layering.sh,check-banned-constructs.sh,check-log-components.sh,check-version.sh,check-hardening.sh: clean.