Class MqttClientWillBuilder


  • public final class MqttClientWillBuilder
    extends Object
    High-level builder for configuring a client Last Will on PlccomMqttClientBuilder.

    The builder mirrors the everyday MQTT Last Will workflow: choose the Will Topic, provide the Last Will payload, optionally select QoS and Retain, then return to the parent client builder with done(). MQTT 5 Will Properties are exposed as optional hints; they are encoded only for MQTT 5 connections, while MQTT 3.1.1 connections continue to send the classic Will Topic, payload, QoS and Retain fields.

    • Method Detail

      • qos0

        public MqttClientWillBuilder qos0()
        Selects QoS 0 for the Last Will publication.
        Returns:
        this builder
      • qos1

        public MqttClientWillBuilder qos1()
        Selects QoS 1 for the Last Will publication.
        Returns:
        this builder
      • qos2

        public MqttClientWillBuilder qos2()
        Selects QoS 2 for the Last Will publication.
        Returns:
        this builder
      • retain

        public MqttClientWillBuilder retain()
        Enables the Last Will Retain flag.
        Returns:
        this builder
      • retain

        public MqttClientWillBuilder retain​(boolean value)
        Sets the Last Will Retain flag.
        Parameters:
        value - true to ask the broker to retain the Will
        Returns:
        this builder
      • payloadFormatUtf8

        public MqttClientWillBuilder payloadFormatUtf8​(Boolean value)
        Sets the MQTT 5 Will Payload Format Indicator property.

        Use true when the Last Will payload is valid UTF-8 character data and false when the payload should be treated as unspecified binary data. Supplying null omits the property.

        Parameters:
        value - payload format hint, or null to omit the property
        Returns:
        this builder
      • payloadFormatUtf8

        public MqttClientWillBuilder payloadFormatUtf8()
        Declares the Last Will payload as UTF-8 character data for MQTT 5 receivers.
        Returns:
        this builder
      • payloadFormatBytes

        public MqttClientWillBuilder payloadFormatBytes()
        Declares the Last Will payload as unspecified binary data for MQTT 5 receivers.
        Returns:
        this builder
      • messageExpirySeconds

        public MqttClientWillBuilder messageExpirySeconds​(Long value)
        Sets the MQTT 5 Will Message Expiry Interval property.

        The broker starts the expiry timer when it publishes the Will. A value of 0 means the Will expires immediately, while null lets the broker apply its default behavior.

        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 MqttClientWillBuilder messageExpirySeconds​(long value)
        Sets the MQTT 5 Will 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
      • willDelaySeconds

        public MqttClientWillBuilder willDelaySeconds​(Long value)
        Sets the MQTT 5 Will Delay Interval property.

        The broker waits for this duration after an ungraceful disconnect before publishing the Will. If the same client reconnects before the delay expires, a compliant broker can cancel the pending Will.

        Parameters:
        value - delay interval in seconds, or null to omit the property
        Returns:
        this builder
        Throws:
        IllegalArgumentException - if value is outside the MQTT unsigned 32-bit range
      • willDelaySeconds

        public MqttClientWillBuilder willDelaySeconds​(long value)
        Sets the MQTT 5 Will Delay Interval property.
        Parameters:
        value - delay interval in seconds
        Returns:
        this builder
        Throws:
        IllegalArgumentException - if value is outside the MQTT unsigned 32-bit range
      • contentType

        public MqttClientWillBuilder contentType​(String value)
        Sets the MQTT 5 Will Content Type property.
        Parameters:
        value - content type, or null to omit the property
        Returns:
        this builder
      • responseTopic

        public MqttClientWillBuilder responseTopic​(String value)
        Sets the MQTT 5 Will Response Topic property.

        The value is a Topic Name, not a Topic Filter. Wildcards are rejected later by the protocol encoder using the configured client limits.

        Parameters:
        value - response topic, or null to omit the property
        Returns:
        this builder
      • correlationData

        public MqttClientWillBuilder correlationData​(byte[] value)
        Sets the MQTT 5 Will Correlation Data property.
        Parameters:
        value - correlation data bytes, or null to omit the property
        Returns:
        this builder