hivemq / hivemq-mqtt-client

HiveMQ MQTT Client is an MQTT 5.0 and MQTT 3.1.1 compatible and feature-rich high-performance Java client library with different API flavours and backpressure support
https://hivemq.github.io/hivemq-mqtt-client/
Apache License 2.0
832 stars 153 forks source link

Need configurational fields in MQTT HiveMQ client #555

Closed Shalaka1197 closed 1 year ago

Shalaka1197 commented 1 year ago

Is there any configurational field is present in HiveMQ MQTT client for maxInflight and mqttTimeoutInMillis so that we can pass our own values during client creation ? This fields are present in Paho MQTT client similar I want in HiveMQ MQTT client.

pglombardo commented 1 year ago

Hi @Shalaka1197,

The equivalent for maxInflight would be restrictions().sendMaximum(X).

final Mqtt5ConnAck connAck = client.toBlocking().connectWith()
        .cleanStart(false)          // resume a previous session
        .sessionExpiryInterval(30)  // keep session state for 30s
        .restrictions()
            .receiveMaximum(10)             // receive max. 10 concurrent messages
            .sendMaximum(10)                // send max. 10 concurrent messages
            .maximumPacketSize(10_240)      // receive messages with max size of 10KB
            .sendMaximumPacketSize(10_240)  // send messages with max size of 10KB
            .topicAliasMaximum(0)           // the server should not use topic aliases
            .sendTopicAliasMaximum(8)       // use up to 8 aliases for the most used topics (automatically traced)
            .applyRestrictions()
        .willPublish()
            .topic("demo/topic/will")
            // <snip>
            .applyWillPublish()
        .send();

As for mqttTimeoutInMillis, this Java client uses granular timeouts for various operations such as socket connect, disconnect, publish etc.. What timeout are you looking for? A general broker response timeout?

Shalaka1197 commented 1 year ago

@pglombardo I am looking for connection timeout as of now. Please let me know how to configure it.

pglombardo commented 1 year ago

You can add the following to your client builder code:

.transportConfig()
    .mqttConnectTimeout(10, TimeUnit.SECONDS)
    .socketConnectTimeout(10, TimeUnit.SECONDS)
    .applyTransportConfig()

Also checkout MqttClientTransportConfig

This should be what you're looking for. Let me know.

pglombardo commented 1 year ago

Hi @Shalaka1197 - Did this help out? If anything remains, let me know otherwise I'll close out this issue eventually.

Shalaka1197 commented 1 year ago

Thanks for the reply @pglombardo . You can close this now.