SmartsquareGmbH / mqtt-starter

HiveMQ Spring Boot Starter
MIT License
15 stars 5 forks source link

PublishingOptions without specifying messageExpiryInterval results in publish failure #18

Closed hcrgm closed 1 month ago

hcrgm commented 1 month ago

Hi! I'm using it with MQTT 5. When using options without specifying messageExpiryInterval, the value check in MqttPublishBuilder#messageExpiryInterval will fail.

mqtt5Publisher.publish(topic, MqttQos.AT_LEAST_ONCE, msg,
    Mqtt5Publisher.PublishingOptions.builder().responseTopic(responseTopic).build());
java.lang.IllegalArgumentException: Message expiry interval must not exceed the value range of unsigned int [0, 4294967295], but was 9223372036854775807.
    at com.hivemq.client.internal.util.Checks.unsignedInt(Checks.java:130)
    at com.hivemq.client.internal.mqtt.message.publish.MqttPublishBuilder.messageExpiryInterval(MqttPublishBuilder.java:107)
    at com.hivemq.client.internal.mqtt.message.publish.MqttPublishBuilder$Default.messageExpiryInterval(MqttPublishBuilder.java:193)
    at de.smartsquare.starter.mqtt.Mqtt5Publisher.publish(MqttPublisher.kt:120)
......

I can make a PR to fix it.

rubengees commented 1 month ago

Ah yes, I see the problem. Weird that the mqtt client lib has a constant that cannot be passed into the builder method.

A PR to fix that would be appreciated!