diff --git a/src/main/java/com/hivemq/client/internal/mqtt/message/publish/MqttPublishBuilder.java b/src/main/java/com/hivemq/client/internal/mqtt/message/publish/MqttPublishBuilder.java index fe603468a..dfb8becf2 100644 --- a/src/main/java/com/hivemq/client/internal/mqtt/message/publish/MqttPublishBuilder.java +++ b/src/main/java/com/hivemq/client/internal/mqtt/message/publish/MqttPublishBuilder.java @@ -104,7 +104,11 @@ public abstract class MqttPublishBuilder> { } public @NotNull B messageExpiryInterval(final long messageExpiryInterval) { - this.messageExpiryInterval = Checks.unsignedInt(messageExpiryInterval, "Message expiry interval"); + if (messageExpiryInterval == -1) { + this.messageExpiryInterval = MqttPublish.NO_MESSAGE_EXPIRY; + } else { + this.messageExpiryInterval = Checks.unsignedInt(messageExpiryInterval, "Message expiry interval"); + } return self(); } diff --git a/src/main/java/com/hivemq/client/mqtt/mqtt5/message/connect/Mqtt5ConnectBuilderBase.java b/src/main/java/com/hivemq/client/mqtt/mqtt5/message/connect/Mqtt5ConnectBuilderBase.java index 98e585141..195f4ef73 100644 --- a/src/main/java/com/hivemq/client/mqtt/mqtt5/message/connect/Mqtt5ConnectBuilderBase.java +++ b/src/main/java/com/hivemq/client/mqtt/mqtt5/message/connect/Mqtt5ConnectBuilderBase.java @@ -69,7 +69,7 @@ public interface Mqtt5ConnectBuilderBase> { /** * Sets the {@link Mqtt5Connect#getSessionExpiryInterval() session expiry interval} in seconds. *

- * The value must be in the range of an unsigned int: [0, 4_294_967_295]. + * The value must be in the range of an unsigned int: [0, 4_294_967_295]. 4_294_967_295 disables session expiry. * * @param sessionExpiryInterval the session expiry interval in seconds. * @return the builder. diff --git a/src/main/java/com/hivemq/client/mqtt/mqtt5/message/publish/Mqtt5PublishBuilderBase.java b/src/main/java/com/hivemq/client/mqtt/mqtt5/message/publish/Mqtt5PublishBuilderBase.java index 93717c410..34104873e 100644 --- a/src/main/java/com/hivemq/client/mqtt/mqtt5/message/publish/Mqtt5PublishBuilderBase.java +++ b/src/main/java/com/hivemq/client/mqtt/mqtt5/message/publish/Mqtt5PublishBuilderBase.java @@ -116,7 +116,7 @@ interface Complete> extends Mqtt5P /** * Sets the {@link Mqtt5Publish#getMessageExpiryInterval() message expiry interval} in seconds. *

- * The value must be in the range of an unsigned int: [0, 4_294_967_295]. + * The value must be in the range of an unsigned int: [0, 4_294_967_295] or -1 to disable message expiry. * * @param messageExpiryInterval the message expiry interval in seconds. * @return the builder.