IRISLIB database
Client Class Reference

This class implements an interface to the eclispse paho-c MQTT client library. More...

Inheritance diagram for Client:
Collaboration diagram for Client:

Public Member Functions

_.Library.Status Connect (_.Library.String username, _.Library.String password, _.Library.Boolean cleansession, _.Library.Integer timeout, _.Library.String sslconfig)
 Connect to the broker specifying username and password if required. More...
 
_.Library.Status Disconnect ()
 Disconnect from the broker. More...
 
_.Library.Status IsConnected (_.Library.Boolean connected)
 Test to see if the client is connected. More...
 
_.Library.Status Publish (_.Library.String topic, _.Library.String message, _.Library.Boolean retain, _.Library.Integer timeout)
 Send a message to a specified topic. More...
 
_.Library.Status Receive (_.Library.String topic, _.Library.String message, _.Library.Integer timeout)
 Listen for a message to be received for up to timeout milliseconds. More...
 
_.Library.Status Subscribe (_.Library.String topic)
 Call this to subscribe to the named topic. More...
 
_.Library.Status Unsubscribe (_.Library.String topic)
 Unsubscribe from a topic. More...
 
- Public Member Functions inherited from RegisteredObject
_.Library.Status OnAddToSaveSet (_.Library.Integer depth, _.Library.Integer insert, _.Library.Integer callcount)
 This callback method is invoked when the current object is added to the SaveSet,. More...
 
_.Library.Status OnConstructClone (_.Library.RegisteredObject object, _.Library.Boolean deep, _.Library.String cloned)
 This callback method is invoked by the <METHOD>ConstructClone</METHOD> method to. More...
 
_.Library.Status OnNew ()
 This callback method is invoked by the <METHOD>New</METHOD> method to. More...
 
_.Library.Status OnValidateObject ()
 This callback method is invoked by the <METHOD>ValidateObject</METHOD> method to. More...
 

Public Attributes

 ClientId
 This holds the client id. More...
 
 TimedOut
 Indicates if the last send or receive operation timed out. More...
 

Static Public Attributes

 DOMAIN = None
 Error Text Domain.
 
- Static Public Attributes inherited from RegisteredObject
 CAPTION = None
 Optional name used by the Form Wizard for a class when generating forms. More...
 
 JAVATYPE = None
 The Java type to be used when exported.
 
 PROPERTYVALIDATION = None
 This parameter controls the default validation behavior for the object. More...
 

Private Member Functions

_.Library.Status OnClose ()
 This callback method is invoked by the <METHOD>Close</METHOD> method to. More...
 
_.Library.Status OnNew (_.Library.String url, _.Library.String clientid, _.Library.Integer qos, _.Library.Integer keepaliveinterval, _.Library.String lwttopic, _.Library.String lwtmessage)
 When creating a new client instance at minimum the url to connect and a client id is required to be specified. More...
 

Private Attributes

 __Handle
 This holds the handle to the library's instance of the MQTT client. More...
 
 __UrlScheme
 This holds the url scheme, tcp or ssl. More...
 

Detailed Description

This class implements an interface to the eclispse paho-c MQTT client library.

Details of of the library can be found here :- https://www.eclipse.org/paho/clients/c.

The client provides the ability to connect to a third-party MQTT broker and publish or subscribe to topics and send/receive messages. MQTT is a light-weight protocol and can provide superior performance to HTTP based messaging. There are many excellent tutorials for MQTT to be found on the internet and one should take the time to become familiar with the basics as although the interface to the client is relatively straight-forward, the behaviors can be sophisticated depending upon which options are selected. All strings passed to the library have the requirement to be utf-8 encoded which includes, but is not limited to, messages, topics, usernames and passwords.

Member Function Documentation

◆ OnClose()

_.Library.Status OnClose ( )
private

This callback method is invoked by the <METHOD>Close</METHOD> method to.

provide notification that the current object is being closed.

The return value of this method is ignored.

Reimplemented from RegisteredObject.

◆ OnNew()

_.Library.Status OnNew ( _.Library.String  url,
_.Library.String  clientid,
_.Library.Integer  qos,
_.Library.Integer  keepaliveinterval,
_.Library.String  lwttopic,
_.Library.String  lwtmessage 
)
private

When creating a new client instance at minimum the url to connect and a client id is required to be specified.

The client id must be a utf-8 string which is used to uniquely identify the client. This takes the form "tcp://localhost:1883" where the scheme is tcp and the host and port are seperated by a colon. If you are using ssl you should specify the url in the form "ssl://localhost:8883" where scheme is ssl. The second parameter is a string which the broker can use to identify the client. The client will generate an id if not specified. The third parameter defines the required quality of service, 'Fire and Forget' or 'Wait for Delivery'. The fourth parameter is the keepalive interval. The client will send keepalive messages to the broker according to the specified interval. The final pair of parameters specifies the last will and testament topic and associated message. The LWT (last will and testament) feature tells the broker to deliver the Last Will message to the Last Will topic, should the client unexpectedly disconnect

Note, New() can error so it's important to check that the return value with $IsObject() and examine the objlasterror status value should the New() not return a valid object.

◆ Connect()

_.Library.Status Connect ( _.Library.String  username,
_.Library.String  password,
_.Library.Boolean  cleansession,
_.Library.Integer  timeout,
_.Library.String  sslconfig 
)

Connect to the broker specifying username and password if required.

The cleansession argument

can be set to 1 if a persistent session is required. Timeout is a connection timeout in seconds. If a secure connection using SSL is required then the name of an IRIS SSL configuration should be passed as the fifth argument. Please consult the documentation for an explanation of what it means to use a persistent session.

◆ Disconnect()

_.Library.Status Disconnect ( )

Disconnect from the broker.

It's important to disconnect from the broker when a connection is

no longer required to free up system resources on both the broker and the client.

◆ IsConnected()

_.Library.Status IsConnected ( _.Library.Boolean  connected)

Test to see if the client is connected.

The library maintains a connection and it can be queried

to determine if the client is currently connected. Disconnects can occur at any time due to network glitches so it's important to be able to determine the connection status.

◆ Publish()

_.Library.Status Publish ( _.Library.String  topic,
_.Library.String  message,
_.Library.Boolean  retain,
_.Library.Integer  timeout 
)

Send a message to a specified topic.

Note that both should be utf-8 encoded. You may pass

1 as the retain argument if you want the broker to retain the message. Additionally if the QOS has been set to $$$QOSWaitForDelivery then the timeout argument will be used for the time to wait for an acknowledgement that the broker has received the message. After calling send you can check the TimedOut property to determine it's status.

◆ Receive()

_.Library.Status Receive ( _.Library.String  topic,
_.Library.String  message,
_.Library.Integer  timeout 
)

Listen for a message to be received for up to timeout milliseconds.

If the timeout expires both the

topic and message will be set to the empty string. Additionally the TimedOut property will be set accordingly

◆ Subscribe()

_.Library.Status Subscribe ( _.Library.String  topic)

Call this to subscribe to the named topic.

The topic must be utf-8 encoded. You must call this method

before you attempt to Receive a message for the named topic.

◆ Unsubscribe()

_.Library.Status Unsubscribe ( _.Library.String  topic)

Unsubscribe from a topic.

After calling this the client will stop receiving messages for the

specific topic. Topic must be utf-8 encoded.

Member Data Documentation

◆ ClientId

ClientId

This holds the client id.

 

◆ __Handle

__Handle
private

This holds the handle to the library's instance of the MQTT client.

 

◆ TimedOut

TimedOut

Indicates if the last send or receive operation timed out.

You can test this following

a successful call to determine if the operation timed out. The timeout on a send is only relevant if you have selected a quality of service which indicates that the broker should confirm receipt of the message ($$$QOSWaitForDelivery specified on the send).  

◆ __UrlScheme

__UrlScheme
private

This holds the url scheme, tcp or ssl.