Hi!
I am working with the HiveMQ MQTT Client (https://github.com/hivemq/hivemq-mqtt-client) and I would like to set som restrictions but I’m not sure I’m doing it right.
I am using the code like this:
final Mqtt5AsyncClient client = Mqtt5Client.builder()
.serverHost("broker.hivemq.com")
.automaticReconnectWithDefaultConfig()
.buildAsync();
final Mqtt5ConnAck connAck = client.toBlocking().connectWith()
.cleanStart(false)
.sessionExpiryInterval(30)
.restrictions()
.receiveMaximum(20)
.sendMaximum(15)
.maximumPacketSize(10_240)
.sendMaximumPacketSize(10_240)
.applyRestrictions()
.willPublish()
.topic("a/b/c/isla")
.qos(MqttQos.EXACTLY_ONCE)
.payload("hello world".getBytes())
.contentType("text/plain")
.applyWillPublish()
.send();
System.out.println("connected " + connAck.getRestrictions());
Printed to console:
connected MqttConnAckRestrictions{receiveMaximum=10, maximumPacketSize=268435460, topicAliasMaximum=5, maximumQos=EXACTLY_ONCE, retainAvailable=true, wildcardSubscriptionAvailable=true, sharedSubscriptionAvailable=true, subscriptionIdentifiersAvailable=true}
- The restrictions are set and used (I think) when sending the message to the broker, but when printing the message
System.out.println("connected " + connAck.getRestrictions());
, the restrictions are back to default values? Why are the restrictions I set not saved, so I can use them later, to send a new message with the same restrictions? - Why is the receive maximum value 10 (see “printed to console” above)? According to this documentation: https://hivemq.github.io/mqtt-cli/docs/shell/connect.html the default value should be 65535. Where does the value 10 come from?
- This code sends one message, but I would like to send multiple messages. How can I connect with restrictions, without sending a message right away? Is there a solution to keep the restrictions I set when connecting, even outside the connect method?
Thanks in advance
Isla