net.sf.xenqtt.message
Class PubMessage

java.lang.Object
  extended by net.sf.xenqtt.message.MqttMessage
      extended by net.sf.xenqtt.message.IdentifiableMqttMessage
          extended by net.sf.xenqtt.message.PubMessage

public final class PubMessage
extends IdentifiableMqttMessage

A PUBLISH message is sent by a client to a server for distribution to interested subscribers. Each PUBLISH message is associated with a topic name (also known as the Subject or Channel). This is a hierarchical name space that defines a taxonomy of information sources for which subscribers can register an interest. A message that is published to a specific topic name is delivered to connected subscribers for that topic.

If a client subscribes to one or more topics, any message published to those topics are sent by the server to the client as a PUBLISH message.


Constructor Summary
PubMessage(ByteBuffer buffer, int remainingLength)
          Used to construct a received message.
PubMessage(QoS qos, boolean retain, String topicName, int messageId, byte[] payload)
          Used to construct a message for sending
 
Method Summary
 int getMessageId()
          The message identifier is present in the variable header of the following MQTT messages: PUBLISH, PUBACK, PUBREC, PUBREL, PUBCOMP, SUBSCRIBE, SUBACK, UNSUBSCRIBE, UNSUBACK.
 byte[] getPayload()
          Contains the data for publishing.
 String getTopicName()
          This must not contain Topic wildcard characters.
 void setMessageId(int messageId)
          Sets the message ID
 
Methods inherited from class net.sf.xenqtt.message.MqttMessage
byteBufferToHex, bytesToHex, equals, getMessageType, getQoS, getQoSLevel, getRemainingLength, isAck, isAckable, isDuplicate, isRetain, setDuplicateFlag, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PubMessage

public PubMessage(ByteBuffer buffer,
                  int remainingLength)
Used to construct a received message.


PubMessage

public PubMessage(QoS qos,
                  boolean retain,
                  String topicName,
                  int messageId,
                  byte[] payload)
Used to construct a message for sending

Method Detail

getTopicName

public String getTopicName()
This must not contain Topic wildcard characters.

When received by a client that subscribed using wildcard characters, this string will be the absolute topic specified by the originating publisher and not the subscription string used by the client.


getMessageId

public int getMessageId()
Description copied from class: IdentifiableMqttMessage
The message identifier is present in the variable header of the following MQTT messages: PUBLISH, PUBACK, PUBREC, PUBREL, PUBCOMP, SUBSCRIBE, SUBACK, UNSUBSCRIBE, UNSUBACK.

The Message Identifier (Message ID) field is only present in messages where the QoS bits in the fixed header indicate QoS levels 1 or 2. See section on Quality of Service levels and flows for more information.

The Message ID is a 16-bit unsigned integer that must be unique amongst the set of "in flight" messages in a particular direction of communication. It typically increases by exactly one from one message to the next, but is not required to do so.

A client will maintain its own list of Message IDs separate to the Message IDs used by the server it is connected to. It is possible for a client to send a PUBLISH with Message ID 1 at the same time as receiving a PUBLISH with Message ID 1.

Do not use Message ID 0. It is reserved as an invalid Message ID.

Override this implementation for messages where the message ID is not at offset 2 of a fixed length message

Overrides:
getMessageId in class IdentifiableMqttMessage
See Also:
IdentifiableMqttMessage.getMessageId()

setMessageId

public void setMessageId(int messageId)
Description copied from class: IdentifiableMqttMessage
Sets the message ID

Override this implementation for messages where the message ID is not at offset 2 of a fixed length message

Overrides:
setMessageId in class IdentifiableMqttMessage
See Also:
IdentifiableMqttMessage.setMessageId(int)

getPayload

public byte[] getPayload()
Contains the data for publishing. The content and format of the data is application specific. It is valid for a PUBLISH to contain a 0-length payload.



Copyright © 2013. All Rights Reserved.