![]() |
PahoMqttCpp
MQTT C++ Client for POSIX and Windows
|
#include <client.h>
Public Types | |
using | ptr_t = std::shared_ptr<client> |
using | qos_collection = async_client::qos_collection |
using | update_connection_handler = async_client::update_connection_handler |
Public Member Functions | |
client (const string &serverURI, const string &clientId=string{}, const persistence_type &persistence=NO_PERSISTENCE) | |
client (const string &serverURI, const string &clientId, int maxBufferedMessages, const persistence_type &persistence=NO_PERSISTENCE) | |
client (const string &serverURI, const string &clientId, const create_options &opts, const persistence_type &persistence=NO_PERSISTENCE) | |
client (const create_options &opts) | |
virtual | ~client () |
virtual connect_response | connect () |
virtual connect_response | connect (connect_options opts) |
virtual connect_response | reconnect () |
virtual void | disconnect () |
virtual void | disconnect (int timeoutMS) |
template<class Rep , class Period > | |
void | disconnect (const std::chrono::duration< Rep, Period > &to) |
virtual string | get_client_id () const |
virtual string | get_server_uri () const |
virtual std::chrono::milliseconds | get_timeout () const |
connect_options | get_connect_options () const |
virtual topic | get_topic (const string &top, int qos=message::DFLT_QOS, bool retained=message::DFLT_RETAINED) |
virtual bool | is_connected () const |
void | set_update_connection_handler (update_connection_handler cb) |
virtual void | publish (string_ref top, const void *payload, size_t n, int qos, bool retained) |
virtual void | publish (string_ref top, const void *payload, size_t n) |
virtual void | publish (const_message_ptr msg) |
virtual void | publish (const message &msg) |
virtual void | set_callback (callback &cb) |
virtual void | set_timeout (int timeoutMS) |
template<class Rep , class Period > | |
void | set_timeout (const std::chrono::duration< Rep, Period > &to) |
virtual subscribe_response | subscribe (const string &topicFilter, const subscribe_options &opts=subscribe_options(), const properties &props=properties()) |
virtual subscribe_response | subscribe (const string &topicFilter, int qos, const subscribe_options &opts=subscribe_options(), const properties &props=properties()) |
virtual subscribe_response | subscribe (const string_collection &topicFilters, const std::vector< subscribe_options > &opts=std::vector< subscribe_options >(), const properties &props=properties()) |
virtual subscribe_response | subscribe (const string_collection &topicFilters, const qos_collection &qos, const std::vector< subscribe_options > &opts=std::vector< subscribe_options >(), const properties &props=properties()) |
virtual unsubscribe_response | unsubscribe (const string &topicFilter, const properties &props=properties()) |
virtual unsubscribe_response | unsubscribe (const string_collection &topicFilters, const properties &props=properties()) |
virtual void | start_consuming () |
virtual void | stop_consuming () |
virtual const_message_ptr | consume_message () |
virtual bool | try_consume_message (const_message_ptr *msg) |
template<typename Rep , class Period > | |
bool | try_consume_message_for (const_message_ptr *msg, const std::chrono::duration< Rep, Period > &relTime) |
template<class Clock , class Duration > | |
bool | try_consume_message_until (const_message_ptr *msg, const std::chrono::time_point< Clock, Duration > &absTime) |
Lightweight client for talking to an MQTT server using methods that block until an operation completes.
using mqtt::client::ptr_t = std::shared_ptr<client> |
Smart pointer type for this object
Type for a collection of QOS values
Handler for updating connection data before an auto-reconnect.
mqtt::client::client | ( | const string & | serverURI, |
const string & | clientId = string{}, | ||
const persistence_type & | persistence = NO_PERSISTENCE ) |
Create a client that can be used to communicate with an MQTT server.
serverURI | the address of the server to connect to, specified as a URI. |
clientId | a client identifier that is unique on the server being connected to. |
persistence | The desired persistence type. |
mqtt::client::client | ( | const string & | serverURI, |
const string & | clientId, | ||
int | maxBufferedMessages, | ||
const persistence_type & | persistence = NO_PERSISTENCE ) |
Create a client that can be used to communicate with an MQTT server, which allows for off-line message buffering. This allows the caller to specify a user-defined persistence object, or use no persistence.
serverURI | the address of the server to connect to, specified as a URI. |
clientId | a client identifier that is unique on the server being connected to |
maxBufferedMessages | the maximum number of messages allowed to be buffered while not connected |
persistence | The desired persistence type. |
mqtt::client::client | ( | const string & | serverURI, |
const string & | clientId, | ||
const create_options & | opts, | ||
const persistence_type & | persistence = NO_PERSISTENCE ) |
Create a client that can be used to communicate with an MQTT server, which allows for off-line message buffering. This allows the caller to specify a user-defined persistence object, or use no persistence.
serverURI | the address of the server to connect to, specified as a URI. |
clientId | a client identifier that is unique on the server being connected to |
opts | The create options |
persistence | The desired persistence type. |
mqtt::client::client | ( | const create_options & | opts | ) |
Create a client that can be used to communicate with an MQTT server.
opts | The create options |
|
inlinevirtual |
Virtual destructor
|
virtual |
Connects to an MQTT server using the default options.
|
virtual |
Connects to an MQTT server using the specified options.
opts | The connect options |
|
virtual |
Reconnects the client using options from the previous connect. The client must have previously called connect() for this to work.
|
virtual |
Disconnects from the server.
|
virtual |
Disconnects from the server.
timeoutMS | the amount of time in milliseconds to allow for existing work to finish before disconnecting. A value of zero or less means the client will not quiesce. |
|
inline |
Disconnects from the server.
to | the amount of time in milliseconds to allow for existing work to finish before disconnecting. A value of zero or less means the client will not quiesce. |
|
inlinevirtual |
Gets the client ID used by this client.
|
inlinevirtual |
Gets the address of the server used by this client.
|
inlinevirtual |
Return the maximum time to wait for an action to complete.
|
inline |
Gets a copy of the connect options that were last used in a request to connect to the broker.
|
inlinevirtual |
Get a topic object which can be used to publish messages on this client.
top | The topic name |
qos | The Quality of Service for the topic |
retained | Whether the published messages set the retain flag. |
|
inlinevirtual |
Determines if this client is currently connected to the server.
|
inline |
Sets a callback to allow the application to update the connection data on automatic reconnects.
cb | The callback functor to register with the library. |
|
inlinevirtual |
Publishes a message to a topic on the server and return once it is delivered.
top | The topic to publish |
payload | The data to publish |
n | The size in bytes of the data |
qos | The QoS for message delivery |
retained | Whether the broker should retain the message |
|
inlinevirtual |
Publishes a message to a topic on the server and return once it is delivered.
top | The topic to publish |
payload | The data to publish |
n | The size in bytes of the data |
|
inlinevirtual |
Publishes a message to a topic on the server.
msg | The message |
|
inlinevirtual |
Publishes a message to a topic on the server. This version will not timeout since that could leave the library with a reference to memory that could disappear while the library is still using it.
msg | The message |
|
virtual |
Sets the callback listener to use for events that happen asynchronously.
cb | The callback functions |
|
inlinevirtual |
Set the maximum time to wait for an action to complete.
timeoutMS | The timeout in milliseconds |
|
inline |
Set the maximum time to wait for an action to complete.
to | The timeout as a std::chrono duration. |
|
virtual |
Subscribe to a topic, which may include wildcards using a QoS of 1. @param topicFilter A single topic to subscribe
maked *
props | The MQTT v5 properties. |
opts | The MQTT v5 subscribe options for the topic |
|
virtual |
Subscribe to a topic, which may include wildcards.
topicFilter | A single topic to subscribe |
qos | The QoS of the subscription |
opts | The MQTT v5 subscribe options for the topic |
props | The MQTT v5 properties. |
|
virtual |
Subscribes to a one or more topics, which may include wildcards using a QoS of 1.
topicFilters | A set of topics to subscribe |
opts | The MQTT v5 subscribe options (one for each topic) |
props | The MQTT v5 properties. |
|
virtual |
Subscribes to multiple topics, each of which may include wildcards.
topicFilters | A collection of topics to subscribe |
qos | A collection of QoS for each topic |
opts | The MQTT v5 subscribe options (one for each topic) |
props | The MQTT v5 properties. |
|
virtual |
Requests the server unsubscribe the client from a topic.
topicFilter | A single topic to unsubscribe. |
props | The MQTT v5 properties. |
|
virtual |
Requests the server unsubscribe the client from one or more topics.
topicFilters | A collection of topics to unsubscribe. |
props | The MQTT v5 properties. |
|
inlinevirtual |
Start consuming messages. This initializes the client to receive messages through a queue that can be read synchronously.
|
inlinevirtual |
Stop consuming messages. This shuts down the internal callback and discards any unread messages.
|
inlinevirtual |
Read the next message from the queue. This blocks until a new message arrives.
|
inlinevirtual |
Try to read the next message from the queue without blocking.
msg | Pointer to the value to receive the message |
|
inline |
Waits a limited time for a message to arrive.
msg | Pointer to the value to receive the message |
relTime | The maximum amount of time to wait for a message. |
|
inline |
Waits until a specific time for a message to occur.
msg | Pointer to the value to receive the message |
absTime | The time point to wait until, before timing out. |