PrevUpHomeNext
mqtt_client::async_publish

Send a PUBLISH packet to Broker to transport an Application Message.

template <
    qos_e qos_type,
    typename CompletionToken = typename asio::default_completion_token<executor_type>::type
>
decltype(auto) async_publish(
    std::string topic,
    std::string payload,
    retain_e retain,
    const publish_props & props,
    CompletionToken && token = {}
);
Description
Template Parameters

Name

Description

qos_type

The qos_e level of assurance for delivery.

Parameters

Name

Description

topic

Identification of the information channel to which Payload data is published.

payload

The Application Message that is being published.

retain

The retain_e flag.

props

An instance of async_mqtt5::publish_props.

token

Completion token that will be used to produce a completion handler. The handler will be invoked when the operation completes. On immediate completion, invocation of the handler will be performed in a manner equivalent to using boost::asio::async_immediate.

Handler signature

The handler signature for this operation depends on the qos_e specified:

qos == qos_e::at_most_once:

void (
  async_mqtt5::error_code  // Result of operation
)

qos == qos_e::at_least_once:

void (
  async_mqtt5::error_code, // Result of operation.
  async_mqtt5::reason_code,  // Reason Code received from Broker.
  async_mqtt5::puback_props  // Properties received in the PUBACK packet.
)

qos == qos_e::exactly_once:

void (
  async_mqtt5::error_code, // Result of operation.
  async_mqtt5::reason_code,  // Reason Code received from Broker.
  async_mqtt5::pubcomp_props // Properties received in the PUBCOMP packet.
)
Completion condition

Depending on the qos_e specified, the asynchronous operation will complete when one of the following conditions is true:

Error codes

The list of all possible error codes that this operation can finish with:

Refer to the section on Error handling to find the underlying causes for each error code.

Per-Operation Cancellation

This asynchronous operation supports cancellation for the following boost::asio::cancellation_type values:


PrevUpHomeNext