Hi @Isla,
I answer here some of your other questions
Your first comment part of 3. This code sends one message ....
Is there a solution to keep the restrictions I set when connecting, even outside the connect method?:
You can build an Mqtt5ConnectRestrictions
and pass it in the connect:
final Mqtt5ConnectRestrictions connectRestrictions = Mqtt5ConnectRestrictions.builder()
.maximumPacketSize(10_000)
.receiveMaximum(10)
.build();
final Mqtt5ConnAck connAck = client.toBlocking().connectWith()
.cleanStart(false)
.sessionExpiryInterval(30)
.restrictions(connectRestrictions)
.willPublish()
.topic("a/b/c/isla")
.qos(MqttQos.EXACTLY_ONCE)
.payload("hello world".getBytes())
.contentType("text/plain")
.applyWillPublish()
.send();
Next question:
You are asking how you can send messages with checking the restrictions.
Answer, there is no need for you to check for example the max packet size or how many unacknowledged message you have currently, as the client is doing this internally for you. One of your code snippet as an example:
for(int i = 0; i < 1000; i++) {
client.toBlocking().publishWith()
.topic("demo/topic/a")
.qos(MqttQos.EXACTLY_ONCE)
.payload(Integer.toString(i).getBytes())
.send();
}
The client will check internally if this PUBLISH message if above the max packet size limit the broker set and will throw an error accordingly.
Next question:
You are asking how to print the client restrictions. Just ask the client (after connecting to the broker):
client.getConfig().getConnectionConfig().ifPresent(restrictions -> {
System.out.println("Client -> Broker restrictions: " + restrictions.getRestrictionsForClient());
System.out.println("Broker -> Client restrictions: " + restrictions.getRestrictionsForServer());
});
Greetings,
Michael from the HiveMQ team