Package com.plccom.mqtt.client
Class MqttAsyncClientPublishBuilder
- java.lang.Object
-
- com.plccom.mqtt.client.MqttAsyncClientPublishBuilder
-
public final class MqttAsyncClientPublishBuilder extends Object
Asynchronous high-level builder for one client-side MQTT PUBLISH operation.The builder mirrors
MqttClientPublishBuilderbut returns aCompletableFuturefromsend(). The actual packet encoding, QoS flow and MQTT 5 validation are still handled by the wrapped synchronous client when the future task executes.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MqttAsyncClientPublishBuildercontentType(String value)Sets the MQTT 5 Content Type property.MqttAsyncClientPublishBuildercorrelationData(byte[] value)Sets the MQTT 5 Correlation Data property.MqttAsyncClientPublishBuildermessageExpirySeconds(long value)Sets the MQTT 5 Message Expiry Interval property.MqttAsyncClientPublishBuildermessageExpirySeconds(Long value)Sets the MQTT 5 Message Expiry Interval property.MqttAsyncClientPublishBuilderpayloadFormatBytes()Declares the payload as unspecified binary data for MQTT 5 receivers.MqttAsyncClientPublishBuilderpayloadFormatUtf8()Declares the payload as UTF-8 character data for MQTT 5 receivers.MqttAsyncClientPublishBuilderpayloadFormatUtf8(Boolean value)Sets the MQTT 5 Payload Format Indicator property.MqttAsyncClientPublishBuilderqos0()Uses QoS 0 for the publish.MqttAsyncClientPublishBuilderqos1()Uses QoS 1 for the publish.MqttAsyncClientPublishBuilderqos2()Uses QoS 2 for the publish.MqttAsyncClientPublishBuilderqualityOfService(PlccomMqttQualityOfService value)Sets the requested publish QoS.MqttAsyncClientPublishBuilderresponseTopic(String value)Sets the MQTT 5 Response Topic property.MqttAsyncClientPublishBuilderretain()Enables the MQTT Retain flag.MqttAsyncClientPublishBuilderretain(boolean value)Sets the MQTT Retain flag.CompletableFuture<MqttPublishResult>send()Schedules the publish operation.MqttAsyncClientPublishBuilderuserProperty(String name, String value)Adds one MQTT 5 User Property.
-
-
-
Method Detail
-
qos0
public MqttAsyncClientPublishBuilder qos0()
Uses QoS 0 for the publish.- Returns:
- this builder
-
qos1
public MqttAsyncClientPublishBuilder qos1()
Uses QoS 1 for the publish.- Returns:
- this builder
-
qos2
public MqttAsyncClientPublishBuilder qos2()
Uses QoS 2 for the publish.- Returns:
- this builder
-
qualityOfService
public MqttAsyncClientPublishBuilder qualityOfService(PlccomMqttQualityOfService value)
Sets the requested publish QoS.- Parameters:
value- requested QoS- Returns:
- this builder
- Throws:
NullPointerException- ifvalueisnull
-
retain
public MqttAsyncClientPublishBuilder retain()
Enables the MQTT Retain flag.- Returns:
- this builder
-
retain
public MqttAsyncClientPublishBuilder retain(boolean value)
Sets the MQTT Retain flag.- Parameters:
value-trueto ask the broker to retain the message- Returns:
- this builder
-
payloadFormatUtf8
public MqttAsyncClientPublishBuilder payloadFormatUtf8(Boolean value)
Sets the MQTT 5 Payload Format Indicator property.- Parameters:
value- payload format hint, ornullto omit the property- Returns:
- this builder
-
payloadFormatUtf8
public MqttAsyncClientPublishBuilder payloadFormatUtf8()
Declares the payload as UTF-8 character data for MQTT 5 receivers.- Returns:
- this builder
-
payloadFormatBytes
public MqttAsyncClientPublishBuilder payloadFormatBytes()
Declares the payload as unspecified binary data for MQTT 5 receivers.- Returns:
- this builder
-
contentType
public MqttAsyncClientPublishBuilder contentType(String value)
Sets the MQTT 5 Content Type property.- Parameters:
value- content type, ornullto omit the property- Returns:
- this builder
-
messageExpirySeconds
public MqttAsyncClientPublishBuilder 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 MqttAsyncClientPublishBuilder 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 MqttAsyncClientPublishBuilder responseTopic(String value)
Sets the MQTT 5 Response Topic property.- Parameters:
value- response topic, ornullto omit the property- Returns:
- this builder
-
correlationData
public MqttAsyncClientPublishBuilder correlationData(byte[] value)
Sets the MQTT 5 Correlation Data property.- Parameters:
value- correlation data bytes, ornullto omit the property- Returns:
- this builder
-
userProperty
public MqttAsyncClientPublishBuilder userProperty(String name, String value)
Adds one MQTT 5 User Property.- Parameters:
name- property namevalue- property value- Returns:
- this builder
- Throws:
NullPointerException- ifnameorvalueisnull
-
send
public CompletableFuture<MqttPublishResult> send()
Schedules the publish operation.- Returns:
- future completed with the publish result; operative MQTT failures are reported through the result quality and inner exception
-
-