Package com.plccom.mqtt.client
Class PlccomMqttPublishMessage.Builder
- java.lang.Object
-
- com.plccom.mqtt.client.PlccomMqttPublishMessage.Builder
-
- Enclosing class:
- PlccomMqttPublishMessage
public static final class PlccomMqttPublishMessage.Builder extends Object
Builder for publish messages.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PlccomMqttPublishMessagebuild()Builds an immutable publish message.PlccomMqttPublishMessage.BuildercontentType(String value)Sets the MQTT 5 content type property.PlccomMqttPublishMessage.BuildercorrelationData(byte[] value)Sets the MQTT 5 correlation data property.PlccomMqttPublishMessage.BuildermessageExpiryIntervalSeconds(Long value)Sets the MQTT 5 message expiry interval.PlccomMqttPublishMessage.Builderpayload(byte[] value)Sets the publish payload.PlccomMqttPublishMessage.BuilderpayloadFormatBytes()Declares the payload as unspecified binary data for MQTT 5 receivers.PlccomMqttPublishMessage.BuilderpayloadFormatUtf8()Declares the payload as UTF-8 character data for MQTT 5 receivers.PlccomMqttPublishMessage.BuilderpayloadFormatUtf8(Boolean value)Sets the MQTT 5 Payload Format Indicator property.PlccomMqttPublishMessage.BuilderqualityOfService(PlccomMqttQualityOfService value)Sets the publish QoS.PlccomMqttPublishMessage.BuilderresponseTopic(String value)Sets the MQTT 5 response topic property.PlccomMqttPublishMessage.Builderretain(boolean value)Sets the MQTT retain flag.PlccomMqttPublishMessage.BuildersubscriptionIdentifier(int value)Adds one MQTT 5 Subscription Identifier to this message view.PlccomMqttPublishMessage.BuildersubscriptionIdentifiers(List<Integer> values)Replaces the MQTT 5 Subscription Identifiers on this message view.PlccomMqttPublishMessage.BuilderuserProperties(List<PlccomMqttUserProperty> values)Replaces the MQTT 5 user properties.PlccomMqttPublishMessage.BuilderuserProperty(String name, String value)Adds one MQTT 5 user property.
-
-
-
Method Detail
-
payload
public PlccomMqttPublishMessage.Builder payload(byte[] value)
Sets the publish payload.- Parameters:
value- payload bytes, ornullto publish an empty payload- Returns:
- this builder
-
qualityOfService
public PlccomMqttPublishMessage.Builder qualityOfService(PlccomMqttQualityOfService value)
Sets the publish QoS.- Parameters:
value- requested QoS- Returns:
- this builder
- Throws:
NullPointerException- ifvalueisnull
-
retain
public PlccomMqttPublishMessage.Builder retain(boolean value)
Sets the MQTT retain flag.- Parameters:
value-trueto ask the broker to retain the message- Returns:
- this builder
-
payloadFormatUtf8
public PlccomMqttPublishMessage.Builder payloadFormatUtf8(Boolean value)
Sets the MQTT 5 Payload Format Indicator property.Use
truewhen the payload is valid UTF-8 character data andfalsewhen the payload should be treated as unspecified binary data. Supplyingnullomits the property.- Parameters:
value- payload format hint, ornullto omit the property- Returns:
- this builder
-
payloadFormatUtf8
public PlccomMqttPublishMessage.Builder payloadFormatUtf8()
Declares the payload as UTF-8 character data for MQTT 5 receivers.- Returns:
- this builder
-
payloadFormatBytes
public PlccomMqttPublishMessage.Builder payloadFormatBytes()
Declares the payload as unspecified binary data for MQTT 5 receivers.- Returns:
- this builder
-
contentType
public PlccomMqttPublishMessage.Builder contentType(String value)
Sets the MQTT 5 content type property.- Parameters:
value- content type, ornullto omit the property- Returns:
- this builder
-
messageExpiryIntervalSeconds
public PlccomMqttPublishMessage.Builder messageExpiryIntervalSeconds(Long value)
Sets the MQTT 5 message expiry interval.- Parameters:
value- expiry interval in seconds, ornullto omit the property- Returns:
- this builder
- Throws:
IllegalArgumentException- ifvalueis outside the MQTT unsigned 32-bit range
-
responseTopic
public PlccomMqttPublishMessage.Builder responseTopic(String value)
Sets the MQTT 5 response topic property.The Response Topic is a Topic Name, not a Topic Filter. Wildcard characters are rejected later by the protocol encoder so the same configured topic limits are used as for normal PUBLISH topics.
- Parameters:
value- response topic, ornullto omit the property- Returns:
- this builder
-
correlationData
public PlccomMqttPublishMessage.Builder correlationData(byte[] value)
Sets the MQTT 5 correlation data property.- Parameters:
value- correlation data bytes, ornullto omit the property- Returns:
- this builder
-
userProperty
public PlccomMqttPublishMessage.Builder userProperty(String name, String value)
Adds one MQTT 5 user property.- Parameters:
name- property namevalue- property value- Returns:
- this builder
- Throws:
NullPointerException- ifnameorvalueisnull
-
userProperties
public PlccomMqttPublishMessage.Builder userProperties(List<PlccomMqttUserProperty> values)
Replaces the MQTT 5 user properties.- Parameters:
values- user properties, ornullto clear the list- Returns:
- this builder
- Throws:
NullPointerException- ifvaluescontains anullelement
-
subscriptionIdentifier
public PlccomMqttPublishMessage.Builder subscriptionIdentifier(int value)
Adds one MQTT 5 Subscription Identifier to this message view.This method is primarily used for inbound messages decoded from a broker. Outbound client PUBLISH packets do not encode Subscription Identifiers because the MQTT 5 specification only allows the property on PUBLISH packets sent by a broker to a subscriber.
- Parameters:
value- Subscription Identifier in the MQTT range1..268435455- Returns:
- this builder
- Throws:
IllegalArgumentException- ifvalueis outside the MQTT range
-
subscriptionIdentifiers
public PlccomMqttPublishMessage.Builder subscriptionIdentifiers(List<Integer> values)
Replaces the MQTT 5 Subscription Identifiers on this message view.- Parameters:
values- identifiers, ornullto clear the list- Returns:
- this builder
- Throws:
NullPointerException- ifvaluescontains anullelementIllegalArgumentException- if any identifier is outside the MQTT range
-
build
public PlccomMqttPublishMessage build()
Builds an immutable publish message.- Returns:
- publish message
- Throws:
NullPointerException- if the topic or QoS isnullIllegalArgumentException- if the topic is empty
-
-