IoT::MQTT

class MQTTClientRemoteObject

File Information

Library: IoT/MQTT
Package: Generated
Header: IoT/MQTT/MQTTClientRemoteObject.h

Description

The interface for MQTT clients.

Implementations are expected to receive their client ID and server URI via an implementation defined configuration mechanism. Once configured, a MQTTClient always uses the same client ID and connects to the same server. A MQTT client should automatically attempt to reconnect if the connection to the server is lost.

A single client instance can either support MQTT version 3.1/3.1.1 or version 5. Which MQTT version is supported by the client is determined when configuring the client.

Users of the class must call the appropriate methods supporting the client's configured MQTT version.

Inheritance

Direct Base Classes: IMQTTClient, Poco::RemotingNG::RemoteObject

All Base Classes: IMQTTClient, Poco::OSP::Service, Poco::RefCountedObject, Poco::RemotingNG::Identifiable, Poco::RemotingNG::RemoteObject

Member Summary

Member Functions: connect, connect5, connectAsync, connectAsync5, connected, connectionInfo, disconnect, disconnect5, event__connectionClosed, event__connectionEstablished, event__connectionLost, event__disconnected, event__messageArrived, event__messageDelivered, event__messagePublished, id, mqttVersion, pendingDeliveryTokens, publish, publish5, publishMessage, publishMessage5, remoting__enableEvents, remoting__enableRemoteEvents, remoting__hasEvents, remoting__typeId, serverURI, statistics, subscribe, subscribe5, subscribeMany, subscribeMany5, subscribedTopics, unsubscribe, unsubscribe5, unsubscribeMany, unsubscribeMany5, waitForCompletion

Inherited Functions: connect, connect5, connectAsync, connectAsync5, connected, connectionInfo, disconnect, disconnect5, duplicate, id, isA, mqttVersion, mutex, pendingDeliveryTokens, publish, publish5, publishMessage, publishMessage5, referenceCount, release, remoting__enableEvents, remoting__enableRemoteEvents, remoting__getURI, remoting__hasEvents, remoting__objectId, remoting__setURI, remoting__typeId, serverURI, statistics, subscribe, subscribe5, subscribeMany, subscribeMany5, subscribedTopics, type, unsubscribe, unsubscribe5, unsubscribeMany, unsubscribeMany5, waitForCompletion

Types Aliases

Ptr

using Ptr = Poco::AutoPtr < MQTTClientRemoteObject >;

Constructors

MQTTClientRemoteObject

MQTTClientRemoteObject(
    const Poco::RemotingNG::Identifiable::ObjectId & oid,
    Poco::SharedPtr < IoT::MQTT::MQTTClient > pServiceObject
);

Destructor

~MQTTClientRemoteObject virtual

virtual ~MQTTClientRemoteObject();

Destroys the MQTTClientRemoteObject.

Member Functions

connect virtual inline

IoT::MQTT::ConnectionInfo connect();

Connects to the server if not already connected.

Normally, the client connects automatically when a message is published or a topic is subscribed to.

Returns a ConnectionInfo object containing information about the connection.

Fires the connected event if successful.

Throws a Poco::IOException if the connection cannot be established.

This method is only supported for MQTT 3.1 and 3.1.1.

connect5 virtual inline

IoT::MQTT::ConnectionInfo connect5(
    const std::vector < IoT::MQTT::Property > & connectProperties = std::vector < IoT::MQTT::Property > (),
    const std::vector < IoT::MQTT::Property > & willProperties = std::vector < IoT::MQTT::Property > ()
);

MQTT V5 version of connect().

Connects to the server if not already connected.

MQTT V5 connect and will properties can be specified.

Normally, the client connects automatically when a message is published or a topic is subscribed to.

Returns a ConnectionInfo object containing information about the connection.

Fires the connected event if successful.

Throws a Poco::IOException if the connection cannot be established.

This method is only supported for MQTT 5.

connectAsync virtual inline

virtual void connectAsync();

Connects to the server if not already connected.

Connecting will be done asynchronously in a background thread.

A successful connection will be reported by firing the connected event.

This method is only supported for MQTT 3.1 and 3.1.1.

connectAsync5 virtual inline

virtual void connectAsync5(
    const std::vector < IoT::MQTT::Property > & connectProperties = std::vector < IoT::MQTT::Property > (),
    const std::vector < IoT::MQTT::Property > & willProperties = std::vector < IoT::MQTT::Property > ()
);

MQTT V5 version of connectAsync().

Connects to the server if not already connected.

MQTT V5 connect and will properties can be specified.

Connecting will be done asynchronously in a background thread.

A successful connection will be reported by firing the connected event.

This method is only supported for MQTT 5.

connected virtual inline

virtual bool connected() const;

Returns true if the client is currently connected to the server.

This method is supported for all MQTT versions.

connectionInfo virtual inline

IoT::MQTT::ConnectionInfo connectionInfo() const;

Returns a ConnectionInfo structure describing the currently active connection. If not connected, the ConnectionInfo's serverURI will be empty.

This method is only supported for all MQTT versions.

disconnect virtual inline

virtual void disconnect(
    int timeout
);

Disconnects from the server.

In order to allow the client time to complete handling of messages that are in-flight when this function is called, a timeout period is specified (in milliseconds). When the timeout period has expired, the client disconnects even if there are still outstanding message acknowledgements. The next time the client connects to the same server, any QoS 1 or 2 messages which have not completed will be retried depending on the clean session settings for both the previous and the new connection.

This method is only supported for MQTT 3.1 and 3.1.1.

disconnect5 virtual inline

virtual void disconnect5(
    int timeout,
    IoT::MQTT::ReasonCode reason = IoT::MQTT::ReasonCode (IoT::MQTT::REASON_NORMAL_DISCONNECTION),
    const std::vector < IoT::MQTT::Property > & properties = std::vector < IoT::MQTT::Property > ()
);

MQTT V5 version of disconnect().

Disconnects from the server.

MQTT V5 reason code and properties can be given.

In order to allow the client time to complete handling of messages that are in-flight when this function is called, a timeout period is specified (in milliseconds). When the timeout period has expired, the client disconnects even if there are still outstanding message acknowledgements. The next time the client connects to the same server, any QoS 1 or 2 messages which have not completed will be retried depending on the clean session settings for both the previous and the new connection.

This method is only supported for MQTT 5.

id virtual inline

const std::string & id() const;

Returns the configured client ID.

This method is only supported for all MQTT versions.

mqttVersion virtual inline

virtual int mqttVersion() const;

Returns the MQTT version supported by this client.

Possible return values are:

  • 0: client supports version 3.1 and 3.1.1
  • 3: client supports only version 3.1
  • 4: client supports only version 3.1.1
  • 5: client supports only version 5

pendingDeliveryTokens virtual inline

std::vector < int > pendingDeliveryTokens();

Returns a vector containing the delivery tokens for all messages still pending delivery.

This method is only supported for all MQTT versions.

publish virtual inline

virtual int publish(
    const std::string & topic,
    const std::string & payload,
    int qos = int (0)
);

Publishes the given message on the given topic, using the given QoS.

Returns a delivery token which can be used with the messageDelivered event to verify that the message has been delivered.

Throws a Poco::IOException if the message cannot be published.

This method is only supported for MQTT 3.1 and 3.1.1.

publish5 virtual inline

IoT::MQTT::PublishResult publish5(
    const std::string & topic,
    const std::string & payload,
    int qos = int (0),
    bool retained = bool (false),
    const std::vector < IoT::MQTT::Property > & properties = std::vector < IoT::MQTT::Property > ()
);

MQTT V5 version of publish().

Publishes the given message on the given topic, using the given QoS.

Returns a PublishResult containing the result of the operation, as well as the delivery token, which can be used with the messageDelivered event to verify that the message has been delivered.

Throws a Poco::IOException if the message cannot be published.

This method is only supported for MQTT 5.

publishMessage virtual inline

virtual int publishMessage(
    const std::string & topic,
    const IoT::MQTT::Message & message
);

Publishes the given message on the given topic.

Returns a delivery token which can be used with the messageDelivered event to verify that the message has been delivered.

Throws a Poco::IOException if the message cannot be published.

This method is only supported for MQTT 3.1 and 3.1.1.

publishMessage5 virtual inline

IoT::MQTT::PublishResult publishMessage5(
    const std::string & topic,
    const IoT::MQTT::Message & message
);

MQTT V5 version of publishMessage().

Publishes the given message on the given topic.

Returns a PublishResult containing the result of the operation, as well as the delivery token, which can be used with the messageDelivered event to verify that the message has been delivered.

Throws a Poco::IOException if the message cannot be published.

This method is only supported for MQTT 5.

remoting__enableEvents virtual

virtual std::string remoting__enableEvents(
    Poco::RemotingNG::Listener::Ptr pListener,
    bool enable = bool (true)
);

remoting__enableRemoteEvents virtual

virtual void remoting__enableRemoteEvents(
    const std::string & protocol
);

remoting__hasEvents virtual

virtual bool remoting__hasEvents() const;

remoting__typeId virtual inline

virtual const Poco::RemotingNG::Identifiable::TypeId & remoting__typeId() const;

serverURI virtual inline

const std::string & serverURI() const;

Returns the configured server URI.

This method is only supported for all MQTT versions.

statistics virtual inline

IoT::MQTT::Statistics statistics() const;

Returns statistics about published and received topics and message counts.

This method is only supported for all MQTT versions.

subscribe virtual inline

virtual void subscribe(
    const std::string & topic,
    int qos = int (0)
);

This function attempts to subscribe the client to a single topic, which may contain wildcards. This call also specifies the Quality of service requested for the subscription.

Throws a Poco::IOException if there was a problem registering the subscription.

This method is only supported for MQTT 3.1 and 3.1.1.

subscribe5 virtual inline

IoT::MQTT::Response subscribe5(
    const std::string & topic,
    int qos = int (0),
    const IoT::MQTT::SubscribeOptions & options = IoT::MQTT::SubscribeOptions (),
    const std::vector < IoT::MQTT::Property > & properties = std::vector < IoT::MQTT::Property > ()
);

MQTT V5 version of subscribe(), which allows to specify options and properties.

This function attempts to subscribe the client to a single topic, which may contain wildcards. This call also specifies the Quality of service requested for the subscription.

Throws a Poco::IOException if there was a problem registering the subscription.

This method is only supported for MQTT 5.

subscribeMany virtual inline

virtual void subscribeMany(
    const std::vector < IoT::MQTT::TopicQoS > & topicsAndQoS
);

This function attempts to subscribe the client to a list of topics (with associated QoS levels), which may contain wildcards.

Throws a Poco::IOException if there was a problem registering the subscriptions.

This method is only supported for MQTT 3.1 and 3.1.1.

subscribeMany5 virtual inline

IoT::MQTT::Response subscribeMany5(
    const std::vector < IoT::MQTT::TopicQoS > & topicsAndQoS,
    const IoT::MQTT::SubscribeOptions & options = IoT::MQTT::SubscribeOptions (),
    const std::vector < IoT::MQTT::Property > & properties = std::vector < IoT::MQTT::Property > ()
);

MQTT V5 version of subscribeMany(), which allows to specify options and properties.

This function attempts to subscribe the client to a list of topics (with associated QoS levels), which may contain wildcards.

Throws a Poco::IOException if there was a problem registering the subscriptions.

This method is only supported for MQTT 5.

subscribedTopics virtual inline

std::vector < IoT::MQTT::TopicQoS > subscribedTopics() const;

Returns a vector containing all currently subscribed topics with their QoS level.

This method is supported for all MQTT versions.

unsubscribe virtual inline

virtual void unsubscribe(
    const std::string & topic
);

This function attempts to remove an existing subscription made by the client.

Throws a Poco::IOException if there was a problem removing the subscription.

This method is only supported for MQTT 3.1 and 3.1.1.

unsubscribe5 virtual inline

IoT::MQTT::Response unsubscribe5(
    const std::string & topic,
    const std::vector < IoT::MQTT::Property > & properties = std::vector < IoT::MQTT::Property > ()
);

MQTT V5 version of unsubscribe(), which allows to specify properties.

This function attempts to remove an existing subscription made by the client.

Throws a Poco::IOException if there was a problem removing the subscription.

This method is only supported for MQTT 5.

unsubscribeMany virtual inline

virtual void unsubscribeMany(
    const std::vector < std::string > & topics
);

This function attempts to remove existing subscriptions to a list of topics made by the specified client.

Throws a Poco::IOException if there was a problem removing the subscriptions.

This method is only supported for MQTT 3.1 and 3.1.1.

unsubscribeMany5 virtual inline

IoT::MQTT::Response unsubscribeMany5(
    const std::vector < std::string > & topics,
    const std::vector < IoT::MQTT::Property > & properties = std::vector < IoT::MQTT::Property > ()
);

MQTT V5 version of unsubscribeMany(), which allows to specify properties.

This function attempts to remove existing subscriptions to a list of topics made by the specified client.

Throws a Poco::IOException if there was a problem removing the subscriptions.

This method is only supported for MQTT 5.

waitForCompletion virtual inline

virtual void waitForCompletion(
    int deliveryToken,
    int timeout
);

Waits for delivery of the message associated with the given deliveryToken.

Waits at most for the length of the given timeout in milliseconds. Throws a Poco::TimeoutException if timeout expires without the message delivery being completed.

This method is only supported for all MQTT versions.

event__connectionClosed protected

void event__connectionClosed();

event__connectionEstablished protected

void event__connectionEstablished(
    const IoT::MQTT::ConnectionEstablishedEvent & data
);

event__connectionLost protected

void event__connectionLost(
    const IoT::MQTT::ConnectionLostEvent & data
);

event__disconnected protected

void event__disconnected(
    const IoT::MQTT::DisconnectedEvent & data
);

event__messageArrived protected

void event__messageArrived(
    const IoT::MQTT::MessageArrivedEvent & data
);

event__messageDelivered protected

void event__messageDelivered(
    const IoT::MQTT::MessageDeliveredEvent & data
);

event__messagePublished protected

void event__messagePublished(
    const IoT::MQTT::MessagePublishedEvent & data
);

Securely control IoT edge devices from anywhere   Connect a Device