public class MqttMessage
extends java.lang.Object
Constructor and Description |
---|
MqttMessage()
Constructs a message with an empty payload, and all other values
set to defaults.
|
MqttMessage(byte[] payload)
Constructs a message with the specified byte array as a payload,
and all other values set to defaults.
|
Modifier and Type | Method and Description |
---|---|
void |
clearPayload()
Clears the payload, resetting it to be empty.
|
int |
getId()
Returns the MQTT id of the message.
|
byte[] |
getPayload()
Returns the payload as a byte array.
|
int |
getQos()
Returns the quality of service for this message.
|
boolean |
isDuplicate()
Returns whether or not this message might be a duplicate of one which has
already been received.
|
boolean |
isRetained()
Returns whether or not this message should be/was retained by the server.
|
void |
setId(int messageId)
This is only to be used internally to provide the MQTT id of a message
received from the server.
|
void |
setPayload(byte[] payload)
Sets the payload of this message to be the specified byte array.
|
void |
setQos(int qos)
Sets the quality of service for this message.
|
void |
setRetained(boolean retained)
Whether or not the publish message should be retained by the messaging engine.
|
java.lang.String |
toString()
Returns a string representation of this message's payload.
|
static void |
validateQos(int qos)
Utility method to validate the supplied QoS value.
|
public MqttMessage()
public MqttMessage(byte[] payload)
public static void validateQos(int qos)
java.lang.IllegalArgumentException
- if value of QoS is not 0, 1 or 2.public byte[] getPayload()
public void clearPayload()
java.lang.IllegalStateException
- if this message cannot be editedpublic void setPayload(byte[] payload)
payload
- the payload for this message.java.lang.IllegalStateException
- if this message cannot be editedjava.lang.NullPointerException
- if no payload is providedpublic boolean isRetained()
true
if the message should be, or was, retained by
the server.setRetained(boolean)
public void setRetained(boolean retained)
true
and with an empty
byte array as the payload e.g. new byte[0]
will clear the
retained message from the server. The default value is false
retained
- whether or not the messaging engine should retain the message.java.lang.IllegalStateException
- if this message cannot be editedpublic int getQos()
setQos(int)
public void setQos(int qos)
MqttCallback.deliveryComplete(IMqttDeliveryToken)
.
Also known as "fire and forget".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.MqttConnectOptions
.
If a persistence mechanism is not specified, the message will not be
delivered in the event of a client failure.qos
- the "quality of service" to use. Set to 0, 1, 2.java.lang.IllegalArgumentException
- if value of QoS is not 0, 1 or 2.java.lang.IllegalStateException
- if this message cannot be editedpublic java.lang.String toString()
toString
in class java.lang.Object
public boolean isDuplicate()
true
if the message might be a duplicate.public void setId(int messageId)
messageId
- public int getId()