Class MqttClientPublishBuilder
- java.lang.Object
-
- com.plccom.mqtt.client.MqttClientPublishBuilder
-
public final class MqttClientPublishBuilder extends Object
High-level builder for one client-side MQTT PUBLISH operation.Use this builder when application code wants to publish one value and then fluently choose MQTT options such as QoS, retain handling and MQTT 5 metadata. The builder creates an immutable publish message when
send()is called and lets the client perform the required MQTT validation and acknowledgement flow.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MqttClientPublishBuildercontentType(String value)Sets the MQTT 5 Content Type property.MqttClientPublishBuildercorrelationData(byte[] value)Sets the MQTT 5 Correlation Data property.MqttClientPublishBuildermessageExpirySeconds(long value)Sets the MQTT 5 Message Expiry Interval property.MqttClientPublishBuildermessageExpirySeconds(Long value)Sets the MQTT 5 Message Expiry Interval property.MqttClientPublishBuilderpayloadFormatBytes()Declares the payload as unspecified binary data for MQTT 5 receivers.MqttClientPublishBuilderpayloadFormatUtf8()Declares the payload as UTF-8 character data for MQTT 5 receivers.MqttClientPublishBuilderpayloadFormatUtf8(Boolean value)Sets the MQTT 5 Payload Format Indicator property.MqttClientPublishBuilderqos0()Uses QoS 0 for the publish.MqttClientPublishBuilderqos1()Uses QoS 1 for the publish.MqttClientPublishBuilderqos2()Uses QoS 2 for the publish.MqttClientPublishBuilderqualityOfService(PlccomMqttQualityOfService value)Sets the requested publish QoS.MqttClientPublishBuilderresponseTopic(String value)Sets the MQTT 5 Response Topic property.MqttClientPublishBuilderretain()Enables the MQTT Retain flag.MqttClientPublishBuilderretain(boolean value)Sets the MQTT Retain flag.MqttPublishResultsend()Sends the publish through the underlying client.MqttClientPublishBuilderuserProperty(String name, String value)Adds one MQTT 5 User Property.
-
-
-
Method Detail
-
qos0
public MqttClientPublishBuilder qos0()
Uses QoS 0 for the publish.- Returns:
- this builder
-
qos1
public MqttClientPublishBuilder qos1()
Uses QoS 1 for the publish.- Returns:
- this builder
-
qos2
public MqttClientPublishBuilder qos2()
Uses QoS 2 for the publish.QoS 2 uses the MQTT exactly-once acknowledgement flow. It is useful when duplicate processing would be more expensive than the additional protocol round trips.
- Returns:
- this builder
-
qualityOfService
public MqttClientPublishBuilder qualityOfService(PlccomMqttQualityOfService value)
Sets the requested publish QoS.- Parameters:
value- requested QoS- Returns:
- this builder
- Throws:
NullPointerException- ifvalueisnull
-
retain
public MqttClientPublishBuilder retain()
Enables the MQTT Retain flag.- Returns:
- this builder
-
retain
public MqttClientPublishBuilder retain(boolean value)
Sets the MQTT Retain flag.- Parameters:
value-trueto ask the broker to retain the message- Returns:
- this builder
-
payloadFormatUtf8
public MqttClientPublishBuilder payloadFormatUtf8(Boolean value)
Sets the MQTT 5 Payload Format Indicator property.Use
truefor UTF-8 character data andfalsefor unspecified binary data. Supplyingnullomits the property. The property is encoded only when the negotiated connection uses MQTT 5.0.- Parameters:
value- payload format hint, ornullto omit the property- Returns:
- this builder
-
payloadFormatUtf8
public MqttClientPublishBuilder payloadFormatUtf8()
Declares the payload as UTF-8 character data for MQTT 5 receivers.- Returns:
- this builder
-
payloadFormatBytes
public MqttClientPublishBuilder payloadFormatBytes()
Declares the payload as unspecified binary data for MQTT 5 receivers.- Returns:
- this builder
-
contentType
public MqttClientPublishBuilder contentType(String value)
Sets the MQTT 5 Content Type property.The property is encoded only when the negotiated connection uses MQTT 5.0. Use media types such as
application/jsonwhen receivers should be able to inspect the payload format without parsing the topic name.- Parameters:
value- content type, ornullto omit the property- Returns:
- this builder
-
messageExpirySeconds
public MqttClientPublishBuilder messageExpirySeconds(Long value)
Sets the MQTT 5 Message Expiry Interval property.- Parameters:
value- expiry interval in seconds, ornullto omit the property- Returns:
- this builder
- Throws:
IllegalArgumentException- ifvalueis outside the MQTT unsigned 32-bit range
-
messageExpirySeconds
public MqttClientPublishBuilder messageExpirySeconds(long value)
Sets the MQTT 5 Message Expiry Interval property.- Parameters:
value- expiry interval in seconds- Returns:
- this builder
- Throws:
IllegalArgumentException- ifvalueis outside the MQTT unsigned 32-bit range
-
responseTopic
public MqttClientPublishBuilder responseTopic(String value)
Sets the MQTT 5 Response Topic property.Response Topic is the standard MQTT 5 request/response hint. It tells a receiver where a reply should be published. The value must be a Topic Name, not a Topic Filter; wildcard characters are rejected by the underlying protocol encoder before the packet is sent.
- Parameters:
value- response topic, ornullto omit the property- Returns:
- this builder
-
correlationData
public MqttClientPublishBuilder correlationData(byte[] value)
Sets the MQTT 5 Correlation Data property.Correlation Data is opaque application-owned binary data. A common pattern is to place a request identifier here so the response handler can match a later message on the response topic to the original request.
- Parameters:
value- correlation data bytes, ornullto omit the property- Returns:
- this builder
-
userProperty
public MqttClientPublishBuilder userProperty(String name, String value)
Adds one MQTT 5 User Property.User Properties are application metadata and may be repeated. The builder keeps insertion order so receivers see the same order in the decoded message.
- Parameters:
name- property namevalue- property value- Returns:
- this builder
- Throws:
NullPointerException- ifnameorvalueisnull
-
send
public MqttPublishResult send()
Sends the publish through the underlying client.- Returns:
- publish result describing the message sent by this operation
-
-