Class MqttClientSubscribeBuilder


  • public final class MqttClientSubscribeBuilder
    extends Object
    High-level builder for one client-side MQTT SUBSCRIBE operation.
    • Method Detail

      • qos2

        public MqttClientSubscribeBuilder qos2()
        Requests QoS 2 for matching messages.

        This is a high-level convenience for callers that want the broker to deliver matching messages with at most the MQTT Exactly Once level. The broker may still grant a lower QoS if its own policy or subscription matching rules require that.

        Returns:
        this builder
      • sharedSubscription

        public MqttClientSubscribeBuilder sharedSubscription​(String shareName)
        Converts the current Topic Filter into an MQTT 5 Shared Subscription.

        A shared subscription lets several clients use the same share name and Topic Filter while the broker delivers each matching publication to only one member of that group. This is the MQTT-standard load-balancing pattern for worker-style consumers. The resulting wire Topic Filter is $share/<shareName>/<topicFilter> and is only valid when the connection uses MQTT 5 and the broker advertises Shared Subscription support.

        Parameters:
        shareName - name of the shared subscription group; it must not be empty and must not contain /, + or #
        Returns:
        this builder
        Throws:
        NullPointerException - if shareName is null
        IllegalArgumentException - if shareName is empty or contains MQTT separator or wildcard characters
      • noLocal

        public MqttClientSubscribeBuilder noLocal()
        Requests the MQTT 5 No Local subscription option.

        When the broker supports the option, messages published by the same Client Identifier are not delivered back to this subscription. The option is only valid for MQTT 5 connections.

        Returns:
        this builder
      • noLocal

        public MqttClientSubscribeBuilder noLocal​(boolean value)
        Sets whether MQTT 5 No Local is requested.
        Parameters:
        value - true to request No Local
        Returns:
        this builder
      • retainAsPublished

        public MqttClientSubscribeBuilder retainAsPublished()
        Requests the MQTT 5 Retain As Published subscription option.

        When the broker supports the option, matching retained live messages keep their original retained flag instead of being normalized by the broker. The option is only valid for MQTT 5 connections.

        Returns:
        this builder
      • retainAsPublished

        public MqttClientSubscribeBuilder retainAsPublished​(boolean value)
        Sets whether MQTT 5 Retain As Published is requested.
        Parameters:
        value - true to request Retain As Published
        Returns:
        this builder
      • retainHandlingSendAtSubscribe

        public MqttClientSubscribeBuilder retainHandlingSendAtSubscribe()
        Requests the MQTT 5 default retained-message replay behavior.
        Returns:
        this builder
      • retainHandlingSendAtSubscribeIfNew

        public MqttClientSubscribeBuilder retainHandlingSendAtSubscribeIfNew()
        Requests retained-message replay only when the subscription is new.
        Returns:
        this builder
      • retainHandlingDoNotSend

        public MqttClientSubscribeBuilder retainHandlingDoNotSend()
        Requests that retained messages are not replayed for this subscription.
        Returns:
        this builder
      • subscriptionIdentifier

        public MqttClientSubscribeBuilder subscriptionIdentifier​(int value)
        Sets the MQTT 5 Subscription Identifier for this SUBSCRIBE packet.

        When a broker accepts the identifier, every matching MQTT 5 PUBLISH delivered because of this subscription carries the same identifier back to the client. This is useful when an application has several overlapping subscriptions and wants to know which subscription caused a message to be delivered. The option is only valid for MQTT 5 connections.

        Parameters:
        value - Subscription Identifier in the MQTT range 1..268435455
        Returns:
        this builder
        Throws:
        IllegalArgumentException - if value is outside the MQTT range
      • noSubscriptionIdentifier

        public MqttClientSubscribeBuilder noSubscriptionIdentifier()
        Clears the MQTT 5 Subscription Identifier.
        Returns:
        this builder
      • onMessage

        public MqttClientSubscribeBuilder onMessage​(MqttMessageListener listener)
        Registers a callback for matching inbound messages.

        The callback is invoked by a client-owned sequential dispatcher thread after the message has been accepted by the underlying client. Messages that match a callback subscription are delivered to the callback and are not also placed into PlccomMqttClient.receive(long). Runtime exceptions thrown by the listener are caught by the dispatcher and do not close the MQTT connection.

        The callback should return quickly. Slow or blocking work should be offloaded to an application executor because a full callback queue creates backpressure and can delay MQTT ACK, QoS and Keep Alive processing.

        Parameters:
        listener - message listener invoked for matching messages
        Returns:
        this builder
        Throws:
        NullPointerException - if listener is null
      • send

        public MqttSubscribeResult send()
        Sends the subscription request through the underlying client.
        Returns:
        subscribe result describing the accepted local request
        Throws:
        UnsupportedOperationException - if a callback listener was supplied for a custom client implementation that does not support the high-level callback dispatcher