public class MqttTopic extends Object
Modifier and Type | Field and Description |
---|---|
static String |
MULTI_LEVEL_WILDCARD
Multi-level wildcard The number sign (#) is a wildcard character that
matches any number of levels within a topic.
|
static String |
MULTI_LEVEL_WILDCARD_PATTERN
Multi-level wildcard pattern(/#)
|
static String |
SINGLE_LEVEL_WILDCARD
Single-level wildcard The plus sign (+) is a wildcard character that
matches only one topic level.
|
static String |
TOPIC_LEVEL_SEPARATOR
The forward slash (/) is used to separate each level within a topic tree
and provide a hierarchical structure to the topic space.
|
static String |
TOPIC_WILDCARDS
Topic wildcards (#+)
|
Constructor and Description |
---|
MqttTopic(String name,
org.eclipse.paho.client.mqttv3.internal.ClientComms comms) |
Modifier and Type | Method and Description |
---|---|
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.
|
static void |
validate(String topicString,
boolean wildcardAllowed)
Validate the topic name or topic filter
|
public static final String TOPIC_LEVEL_SEPARATOR
public static final String MULTI_LEVEL_WILDCARD
public static final String SINGLE_LEVEL_WILDCARD
public static final String MULTI_LEVEL_WILDCARD_PATTERN
public static final String TOPIC_WILDCARDS
public MqttTopic(String name, org.eclipse.paho.client.mqttv3.internal.ClientComms comms)
public MqttDeliveryToken publish(byte[] payload, int qos, boolean retained) throws MqttException, MqttPersistenceException
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.payload
- the byte array to use as the payloadqos
- the Quality of Service. Valid values are 0, 1 or 2.retained
- whether or not this message should be retained by the server.IllegalArgumentException
- if value of QoS is not 0, 1 or 2.MqttException
MqttPersistenceException
publish(MqttMessage)
,
MqttMessage.setQos(int)
,
MqttMessage.setRetained(boolean)
public MqttDeliveryToken publish(MqttMessage message) throws MqttException, MqttPersistenceException
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.message
- the message to publishMqttException
MqttPersistenceException
public String getName()
public String toString()
public static void validate(String topicString, boolean wildcardAllowed)
topicString
- topic name or filterwildcardAllowed
- true if validate topic filter, false otherwiseIllegalArgumentException
- if the topic is invalid