Add auto reconnect support (#31)

* Update mqtt-client.php

* Update ConnectionManager.php

* Update mqtt-client.php

* Update mqtt-client.php

* Update mqtt-client.php

* Update ConnectionManager.php

* Update mqtt-client.php

* Add and normalize auto-reconnect settings

* Add .gitkeep

* Remove .gitkeep

Co-authored-by: Marvin Mall <marvin-mall@msn.com>
This commit is contained in:
iVampireSP.com 2022-11-23 05:26:38 +08:00 committed by GitHub
parent 136ce2cb75
commit fe0cb883e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -101,6 +101,14 @@ return [
// The interval (in seconds) in which the client will send a ping to the broker, // The interval (in seconds) in which the client will send a ping to the broker,
// if no other message has been sent. // if no other message has been sent.
'keep_alive_interval' => env('MQTT_KEEP_ALIVE_INTERVAL', 10), 'keep_alive_interval' => env('MQTT_KEEP_ALIVE_INTERVAL', 10),
// Additional settings for the optional auto-reconnect. The delay between reconnect attempts is in seconds.
'auto_reconnect' => [
'enabled' => env('MQTT_AUTO_RECONNECT_ENABLED', false),
'max_reconnect_attempts' => env('MQTT_AUTO_RECONNECT_MAX_RECONNECT_ATTEMPTS', 3),
'delay_between_reconnect_attempts' => env('MQTT_AUTO_RECONNECT_DELAY_BETWEEN_RECONNECT_ATTEMPTS', 0),
],
], ],
], ],

View File

@ -177,6 +177,9 @@ class ConnectionManager
->setLastWillTopic(Arr::get($config, 'last_will.topic')) ->setLastWillTopic(Arr::get($config, 'last_will.topic'))
->setLastWillMessage(Arr::get($config, 'last_will.message')) ->setLastWillMessage(Arr::get($config, 'last_will.message'))
->setLastWillQualityOfService((int) Arr::get($config, 'last_will.quality_of_service', MqttClient::QOS_AT_MOST_ONCE)) ->setLastWillQualityOfService((int) Arr::get($config, 'last_will.quality_of_service', MqttClient::QOS_AT_MOST_ONCE))
->setRetainLastWill((bool) Arr::get($config, 'last_will.retain', false)); ->setRetainLastWill((bool) Arr::get($config, 'last_will.retain', false))
->setReconnectAutomatically((bool) Arr::get($config, 'auto_reconnect.enabled', false))
->setMaxReconnectAttempts((int) Arr::get($config, 'auto_reconnect.max_reconnect_attempts', 3))
->setDelayBetweenReconnectAttempts((int) Arr::get($config, 'auto_reconnect.delay_between_reconnect_attempts', 0));
} }
} }