Interface PublishBuilder
-
@DoNotImplement public interface PublishBuilder
This builder must be used to create aPublish
.Either from values, from a
PublishPacket
or aPublish
.Every Publish built by this builder is fully validated against HiveMQ configuration.
- Since:
- 4.0.0, CE 2019.1
-
-
Method Summary
-
-
-
Method Detail
-
fromPublish
@NotNull PublishBuilder fromPublish(@NotNull PublishPacket publishPacket)
Create aPublish
from the values of aPublishPacket
.- Parameters:
publishPacket
- The publish packet to build aPublish
from.- Returns:
- The
PublishBuilder
. - Throws:
NullPointerException
- If the publish packet is null.DoNotImplementException
- If thePublishPacket
is implemented by the extension.- Since:
- 4.0.0, CE 2019.1
-
fromPublish
@NotNull PublishBuilder fromPublish(@NotNull Publish publish)
- Parameters:
publish
- The publish to build aPublish
from.- Returns:
- The
PublishBuilder
. - Throws:
NullPointerException
- If the publish is null.DoNotImplementException
- If thePublish
is implemented by the extension.- Since:
- 4.0.0, CE 2019.1
-
qos
@NotNull PublishBuilder qos(@NotNull Qos qos)
Sets the quality of service.DEFAULT:
QoS 0
.- Parameters:
qos
- TheQos
to set.- Returns:
- The
PublishBuilder
. - Throws:
NullPointerException
- If the qos is null.IllegalArgumentException
- If qos is higher than the maximum configured qos by HiveMQ. Default is QoS 2.- Since:
- 4.0.0, CE 2019.1
-
retain
@NotNull PublishBuilder retain(boolean retain)
Sets the retain flag.DEFAULT: false
- Parameters:
retain
- The retain flag to set.- Returns:
- The
PublishBuilder
. - Throws:
IllegalArgumentException
- If retain istrue
, but retained messages are disabled by HiveMQ.- Since:
- 4.0.0, CE 2019.1
-
topic
@NotNull PublishBuilder topic(@NotNull String topic)
Sets the topic.This value has no default and must be set.
- Parameters:
topic
- The topic to set.- Returns:
- The
PublishBuilder
. - Throws:
NullPointerException
- If the topic is null.IllegalArgumentException
- If the topic is an empty string.IllegalArgumentException
- If the topic is invalid for publish messages (i.e containing wildcards}.- Since:
- 4.0.0, CE 2019.1
-
payloadFormatIndicator
@NotNull PublishBuilder payloadFormatIndicator(@Nullable PayloadFormatIndicator payloadFormatIndicator)
Sets the payload format indicator.DEFAULT:
null
.- Parameters:
payloadFormatIndicator
- The payload format indicator to set.- Returns:
- The
PublishBuilder
. - Since:
- 4.0.0, CE 2019.1
-
messageExpiryInterval
@NotNull PublishBuilder messageExpiryInterval(long messageExpiryInterval)
Sets the message expiry interval in seconds.DEFAULT:
no expiry
.The default can be changed by configuring
<message-expiry>
in the<mqtt>
config in the config.xml.- Parameters:
messageExpiryInterval
- The message expiry interval to set.- Returns:
- The
PublishBuilder
. - Throws:
IllegalArgumentException
- If the message expiry interval is less than zero or more than the configured maximum by HiveMQ. Default is no expiry.- Since:
- 4.0.0, CE 2019.1
-
responseTopic
@NotNull PublishBuilder responseTopic(@Nullable String responseTopic)
Sets the response topic.DEFAULT:
null
.- Parameters:
responseTopic
- The response topic to set.- Returns:
- The
PublishBuilder
. - Throws:
IllegalArgumentException
- If the response topic is not a valid UTF-8 string.IllegalArgumentException
- If the response topic exceeds the UTF-8 string length limit.- Since:
- 4.0.0, CE 2019.1
-
correlationData
@NotNull PublishBuilder correlationData(@Nullable ByteBuffer correlationData)
Sets the correlation data.DEFAULT:
null
.- Parameters:
correlationData
- The correlation data to set.- Returns:
- The
PublishBuilder
. - Since:
- 4.0.0, CE 2019.1
-
contentType
@NotNull PublishBuilder contentType(@Nullable String contentType)
Sets the content type.DEFAULT:
null
.- Parameters:
contentType
- The content type to set.- Returns:
- The
PublishBuilder
. - Throws:
IllegalArgumentException
- If the content type is not a valid UTF-8 string.IllegalArgumentException
- If the content type exceeds the UTF-8 string length limit.- Since:
- 4.0.0, CE 2019.1
-
payload
@NotNull PublishBuilder payload(@NotNull ByteBuffer payload)
Sets the payload.This value has no default and must be set.
- Parameters:
payload
- The payload to set.- Returns:
- The
PublishBuilder
. - Throws:
NullPointerException
- If the payload is null.- Since:
- 4.0.0, CE 2019.1
-
userProperty
@NotNull PublishBuilder userProperty(@NotNull String key, @NotNull String value)
Adds a user property.DEFAULT:
empty list
.- Parameters:
key
- The key of the user property to add.value
- The value of the user property to add.- Returns:
- The
PublishBuilder
. - Throws:
NullPointerException
- If the key or the value is null.IllegalArgumentException
- If the key or value is not a valid UTF-8 string.IllegalArgumentException
- If the key or value exceeds the UTF-8 string length limit.- Since:
- 4.0.0, CE 2019.1
-
build
@NotNull Publish build()
Builds thePublish
with the provided values or default values.- Returns:
- A
Publish
with the set parameters. - Throws:
NullPointerException
- If the topic or the payload is null.- Since:
- 4.0.0, CE 2019.1
-
-