Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

boost::mqtt5::mqtt_client::async_receive
PrevUpHomeNext

Asynchronously receive an Application Message.

Synopsis
template<
    typename CompletionToken = typename asio::default_completion_token<boost::mqtt5::mqtt_client::executor_type>::type>
decltype(auto)
async_receive(
    CompletionToken&& token = {});
Description

The Client will receive and complete deliveries for all the PUBLISH packets received from the Broker throughout its lifetime. The Client will store them internally in the order they were delivered. Calling this function will attempt to receive an Application Message from internal storage.

Remarks

It is only recommended to call this function if you have established a successful Subscription to a Topic using the async_subscribe function.

Parameters

Name

Description

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

Handler signature

The handler signature for this operation:

void (
    boost::mqtt5::error_code, // Result of operation.
    std::string,    // Topic, the origin of the Application Message.
    std::string,    // Payload, the content of the Application Message.
    boost::mqtt5::publish_props, // Properties received in the PUBLISH packet.
)
Completion condition

The asynchronous operation will complete when one of the following conditions is true:

  • The Client has a pending Application Message in its internal storage ready to be received.
  • An error occurred. This is indicated by an associated boost::mqtt5::error_code in the handler.
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:

  • cancellation_type::terminal
  • cancellation_type::partial
  • cancellation_type::total

PrevUpHomeNext