Class MqttAsyncClientPublishBuilder


  • public final class MqttAsyncClientPublishBuilder
    extends Object
    Asynchronous high-level builder for one client-side MQTT PUBLISH operation.

    The builder mirrors MqttClientPublishBuilder but returns a CompletableFuture from send(). The actual packet encoding, QoS flow and MQTT 5 validation are still handled by the wrapped synchronous client when the future task executes.

    • Method Detail

      • retain

        public MqttAsyncClientPublishBuilder retain​(boolean value)
        Sets the MQTT Retain flag.
        Parameters:
        value - true to 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, or null to 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, or null to 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, or null to omit the property
        Returns:
        this builder
        Throws:
        IllegalArgumentException - if value is 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 - if value is outside the MQTT unsigned 32-bit range
      • responseTopic

        public MqttAsyncClientPublishBuilder responseTopic​(String value)
        Sets the MQTT 5 Response Topic property.
        Parameters:
        value - response topic, or null to omit the property
        Returns:
        this builder
      • correlationData

        public MqttAsyncClientPublishBuilder correlationData​(byte[] value)
        Sets the MQTT 5 Correlation Data property.
        Parameters:
        value - correlation data bytes, or null to omit the property
        Returns:
        this builder
      • 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