-
public class MqttMessageAn MQTT message holds the application payload and options specifying how the message is to be delivered The message includes a "payload" (the body of the message) represented as a byte[].
-
-
Constructor Summary
Constructors Constructor Description MqttMessage()Constructs a message with an empty payload, and all other values set to defaults. MqttMessage(Array<byte> payload)Constructs a message with the specified byte array as a payload, and all other values set to defaults.
-
Method Summary
Modifier and Type Method Description Array<byte>getPayload()Returns the payload as a byte array. voidsetPayload(Array<byte> payload)Sets the payload of this message to be the specified byte array. intgetQos()Returns the quality of service for this message. voidsetQos(int qos)Sets the quality of service for this message. voidsetRetained(boolean retained)Whether or not the publish message should be retained by the messaging engine. static voidvalidateQos(int qos)Utility method to validate the supplied QoS value. voidclearPayload()Clears the payload, resetting it to be empty. booleanisRetained()Returns whether or not this message should be/was retained by the server. StringtoString()Returns a string representation of this message's payload. booleanisDuplicate()Returns whether or not this message might be a duplicate of one which has already been received. intuniqueCode()-
-
Constructor Detail
-
MqttMessage
MqttMessage()
Constructs a message with an empty payload, and all other values set to defaults.
-
MqttMessage
MqttMessage(Array<byte> payload)
Constructs a message with the specified byte array as a payload, and all other values set to defaults.
-
-
Method Detail
-
getPayload
Array<byte> getPayload()
Returns the payload as a byte array.
-
setPayload
void setPayload(Array<byte> payload)
Sets the payload of this message to be the specified byte array.
- Parameters:
payload- the payload for this message.
-
getQos
int getQos()
Returns the quality of service for this message.
-
setQos
void setQos(int qos)
Sets the quality of service for this message.
- Quality of Service 0 - indicates that a message should be delivered at most once (zero or one times). The message will not be persisted to disk, and will not be acknowledged across the network. This QoS is the fastest, but should only be used for messages which are not valuable - note that if the server cannot process the message (for example, there is an authorization problem), then an deliveryComplete. Also known as "fire and forget".
- Quality of Service 1 - indicates that a message should be delivered at least once (one or more times). The message can only be delivered safely if it can be persisted, so the application must supply a means of persistence using
MqttConnectOptions. If a persistence mechanism is not specified, the message will not be delivered in the event of a client failure. The message will be acknowledged across the network. This is the default QoS. - Quality of Service 2 - indicates that a message should be delivered once. The message will be persisted to disk, and will be subject to a two-phase acknowledgement across the network. The message can only be delivered safely if it can be persisted, so the application must supply a means of persistence using
MqttConnectOptions. If a persistence mechanism is not specified, the message will not be delivered in the event of a client failure.
- Parameters:
qos- the "quality of service" to use.
-
setRetained
void setRetained(boolean retained)
Whether or not the publish message should be retained by the messaging engine. Sending a message with the retained set to
falsewill clear the retained message from the server. The default value isfalse- Parameters:
retained- whether or not the messaging engine should retain the message.
-
validateQos
static void validateQos(int qos)
Utility method to validate the supplied QoS value.
-
clearPayload
void clearPayload()
Clears the payload, resetting it to be empty.
-
isRetained
boolean isRetained()
Returns whether or not this message should be/was retained by the server. For messages received from the server, this method returns whether or not the message was from a current publisher, or was "retained" by the server as the last message published on the topic.
-
toString
String toString()
Returns a string representation of this message's payload. Makes an attempt to return the payload as a string. As the MQTT client has no control over the content of the payload it may fail.
-
isDuplicate
boolean isDuplicate()
Returns whether or not this message might be a duplicate of one which has already been received. This will only be set on messages received from the server.
-
uniqueCode
int uniqueCode()
-
-
-
-