Class MqttClientSubscribeBuilder
- java.lang.Object
-
- com.plccom.mqtt.client.MqttClientSubscribeBuilder
-
public final class MqttClientSubscribeBuilder extends Object
High-level builder for one client-side MQTT SUBSCRIBE operation.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MqttClientSubscribeBuildermaximumQualityOfService(PlccomMqttQualityOfService value)Sets the requested maximum QoS.MqttClientSubscribeBuildernoLocal()Requests the MQTT 5 No Local subscription option.MqttClientSubscribeBuildernoLocal(boolean value)Sets whether MQTT 5 No Local is requested.MqttClientSubscribeBuildernoSubscriptionIdentifier()Clears the MQTT 5 Subscription Identifier.MqttClientSubscribeBuilderonMessage(MqttMessageListener listener)Registers a callback for matching inbound messages.MqttClientSubscribeBuilderqos0()Requests QoS 0 for matching messages.MqttClientSubscribeBuilderqos1()Requests QoS 1 for matching messages.MqttClientSubscribeBuilderqos2()Requests QoS 2 for matching messages.MqttClientSubscribeBuilderretainAsPublished()Requests the MQTT 5 Retain As Published subscription option.MqttClientSubscribeBuilderretainAsPublished(boolean value)Sets whether MQTT 5 Retain As Published is requested.MqttClientSubscribeBuilderretainHandling(PlccomMqttRetainHandling value)Sets the MQTT 5 Retain Handling subscription option.MqttClientSubscribeBuilderretainHandlingDoNotSend()Requests that retained messages are not replayed for this subscription.MqttClientSubscribeBuilderretainHandlingSendAtSubscribe()Requests the MQTT 5 default retained-message replay behavior.MqttClientSubscribeBuilderretainHandlingSendAtSubscribeIfNew()Requests retained-message replay only when the subscription is new.MqttSubscribeResultsend()Sends the subscription request through the underlying client.MqttClientSubscribeBuildersharedSubscription(String shareName)Converts the current Topic Filter into an MQTT 5 Shared Subscription.MqttClientSubscribeBuildersubscriptionIdentifier(int value)Sets the MQTT 5 Subscription Identifier for this SUBSCRIBE packet.
-
-
-
Method Detail
-
qos0
public MqttClientSubscribeBuilder qos0()
Requests QoS 0 for matching messages.- Returns:
- this builder
-
qos1
public MqttClientSubscribeBuilder qos1()
Requests QoS 1 for matching messages.- Returns:
- this builder
-
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
-
maximumQualityOfService
public MqttClientSubscribeBuilder maximumQualityOfService(PlccomMqttQualityOfService value)
Sets the requested maximum QoS.- Parameters:
value- requested maximum QoS- Returns:
- this builder
- Throws:
NullPointerException- ifvalueisnull
-
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- ifshareNameisnullIllegalArgumentException- ifshareNameis 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-trueto 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-trueto 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
-
retainHandling
public MqttClientSubscribeBuilder retainHandling(PlccomMqttRetainHandling value)
Sets the MQTT 5 Retain Handling subscription option.- Parameters:
value- retained-message replay behavior- Returns:
- this builder
- Throws:
NullPointerException- ifvalueisnull
-
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 range1..268435455- Returns:
- this builder
- Throws:
IllegalArgumentException- ifvalueis 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- iflistenerisnull
-
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
-
-