org.eclipse.paho.client.mqttv3
Class MqttTopic

java.lang.Object
  extended by org.eclipse.paho.client.mqttv3.MqttTopic

public class MqttTopic
extends Object

Represents a topic destination, used for publish/subscribe messaging.


Constructor Summary
MqttTopic(String name, ClientComms comms)
           
 
Method Summary
 String getName()
          Returns the name of the queue or topic.
 MqttDeliveryToken publish(byte[] payload, int qos, boolean retained)
          Publishes a message on the topic.
 MqttDeliveryToken publish(MqttMessage message)
          Publishes the specified message to this topic, but does not wait for delivery of the message to complete.
 String toString()
          Returns a string representation of this topic.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MqttTopic

public MqttTopic(String name,
                 ClientComms comms)
Method Detail

publish

public MqttDeliveryToken publish(byte[] payload,
                                 int qos,
                                 boolean retained)
                          throws MqttException,
                                 MqttPersistenceException
Publishes a message on the topic. This is a convenience method, which will create a new MqttMessage object with a byte array payload and the specified QoS, and then publish it. All other values in the message will be set to the defaults.

Parameters:
payload - the byte array to use as the payload
qos - the Quality of Service. Valid values are 0, 1 or 2.
retained - whether or not this message should be retained by the server.
Throws:
IllegalArgumentException - if value of QoS is not 0, 1 or 2.
MqttException
MqttPersistenceException
See Also:
publish(MqttMessage), MqttMessage.setQos(int), MqttMessage.setRetained(boolean)

publish

public MqttDeliveryToken publish(MqttMessage message)
                          throws MqttException,
                                 MqttPersistenceException
Publishes the specified message to this topic, but does not wait for delivery of the message to complete. The returned token can be used to track the delivery status of the message. Once this method has returned cleanly, the message has been accepted for publication by the client. Message delivery will be completed in the background when a connection is available.

Parameters:
message - the message to publish
Returns:
an MqttDeliveryToken for tracking the delivery of the message
Throws:
MqttException
MqttPersistenceException

getName

public String getName()
Returns the name of the queue or topic.

Returns:
the name of this destination.

toString

public String toString()
Returns a string representation of this topic.

Overrides:
toString in class Object
Returns:
a string representation of this topic.


Copyright © 2013. All Rights Reserved.