Send a SUBSCRIBE
packet to Broker
to create a subscription to one or more Topics of interest.
template < typename CompletionToken = typename asio::default_completion_token<executor_type>::type > decltype(auto) async_subscribe( const std::vector< subscribe_topic > & topics, const subscribe_props & props, CompletionToken && token = {} );
After the subscription has been established, the Broker will send PUBLISH
packets to the Client to forward Application Messages that were published
to Topics that the Client subscribed to. The Application Messages can
be received with mqtt_client::async_receive
function.
Name |
Description |
---|---|
topics |
A list of |
props |
An instance of |
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 |
The handler signature for this operation:
void (, // Result of operation. std::vector<
async_mqtt5::error_code
>, // Vector of Reason Codes indicating // the subscription result for each Topic // in the SUBSCRIBE packet.
async_mqtt5::reason_code
async_mqtt5::suback_props
, // Properties received in the SUBACK packet. )
The asynchronous operation will complete when one of the following conditions is true:
SUBSCRIBE
packet and has
received a SUBACK
response from the
Broker.
async_mqtt5::error_code
in
the handler.
The list of all possible error codes that this operation can finish with:
boost::system::errc::errc_t::success
boost::asio::error::no_recovery
boost::asio::error::operation_aborted
async_mqtt5::client::error::malformed_packet
async_mqtt5::client::error::packet_too_large
async_mqtt5::client::error::pid_overrun
async_mqtt5::client::error::invalid_topic
async_mqtt5::client::error::wildcard_subscription_not_available
async_mqtt5::client::error::subscription_identifier_not_available
async_mqtt5::client::error::shared_subscription_not_available
Refer to the section on
to find the underlying causes for each error code.
Error handling
This asynchronous operation supports cancellation for the following
boost::asio::cancellation_type
values:
cancellation_type::terminal
- invokes mqtt_client::cancel
cancellation_type::partial
& cancellation_type::total
- prevents potential resending of the SUBSCRIBE
packet