1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-26 13:48:53 +08:00

NOISSUE - Fix MQTT Forwarder client id (#1309)

* Fix MQTT Forwarder client ID

Don't set client ID for MQTT client in MQTT forwarder. It results in
error in case of multiple instances of the MQTT adapter because they all
share MQTT client ID, which makes broker disconnect all the other
adapters.

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Inline broker address option

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Add MQTT client username

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

Co-authored-by: Drasko DRASKOVIC <drasko.draskovic@gmail.com>
This commit is contained in:
Dušan Borovčanin 2020-12-17 17:17:33 +01:00 committed by GitHub
parent d2af0602a0
commit 1810cec82b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,19 +12,16 @@ import (
const ( const (
protocol = "mqtt" protocol = "mqtt"
id = "mqtt-publisher" username = "mainflux-mqtt"
qos = 1 qos = 2
) )
var errConnect = errors.New("failed to connect to MQTT broker") var errConnect = errors.New("failed to connect to MQTT broker")
func newClient(address string, timeout time.Duration) (mqtt.Client, error) { func newClient(address string, timeout time.Duration) (mqtt.Client, error) {
opts := mqtt.NewClientOptions(). opts := mqtt.NewClientOptions().
AddBroker(address). SetUsername(username).
SetUsername(id). AddBroker(address)
SetPassword(id).
SetClientID(id).
SetCleanSession(false)
client := mqtt.NewClient(opts) client := mqtt.NewClient(opts)
token := client.Connect() token := client.Connect()
if token.Error() != nil { if token.Error() != nil {