axl_bool myqtt_conn_pub ( MyQttConn conn,
const char *  topic_name,
const axlPointer  app_message,
int  app_message_size,
MyQttQos  qos,
axl_bool  retain,
int  wait_publish 
)

Allows to publish a new application message with the provided topic name on the provided connection.

The function will publish the application message provided with the QOS indicated.

Optionally, the function allows to wait for publish operation to fully complete blocking the caller until that is done. For MYQTT_QOS_AT_MOST_ONCE (Qos 1) this has no effect. But for MYQTT_QOS_AT_LEAST_ONCE_DELIVERY (QoS 1) it implies waiting for PUBACK control packet to be received. The same applies to MYQTT_QOS_EXACTLY_ONCE_DELIVERY (QoS 2) which implies waiting until PUBCOMP is received.

Parameters
connThe connection where the publish operation will take place.
topic_nameThe name of the topic for the application message published.
app_messageThe application message to publish. From MyQtt's perspective, this is binary data that has a format that is only meaningful to the application on top using MQTT.
app_message_sizeThe size of the application message.
qosThe quality of service under which the message will be published. See MyQttQos
retainEnable message retention for this published message. This way new subscribers will be able to get last published retained message.
wait_publishWait for full publication of the message blocking the caller until that happens. If 0 is provided no wait is performed. If some value is provided that will be the max amount of time, in seconds, to wait for complete publication. For MYQTT_QOS_0 this value is ignored.
Returns
The function returns axl_true in the case the message was published, otherwise axl_false is returned. The function returns axl_false when the connection received is broken or topic name is NULL or it is bigger than 65535 bytes.

A note about closing connection right away after publication

Please, note that if you want to close the connection (myqtt_conn_close) just after publication (myqtt_conn_pub) it is recommended to setup a wait for publish (wait_publish param) to ensure the function returns after actually publishing the message and after undergoing with all exchanges that are required according to the provided QoS.

References msg, myqtt_conn_is_ok(), MYQTT_PUBLISH, MYQTT_QOS_SKIP_STORAGE, and myqtt_storage_store_msg().