gost / server

GOST - Go implementation of OGC SensorThings API
MIT License
61 stars 19 forks source link

Subscription to topics after re-connecting to MQTT broker #151

Closed dschowta closed 6 years ago

dschowta commented 6 years ago

I have learned that the the GOST server does not re-connect to MQTT broker after it looses connection with the broker (for more than say 5 minutes). Because of this, GOST server might not get lots of incoming observations until it is restarted manually. It would be really great if this is addressed. Thanks in advance.

bertt commented 6 years ago

I've checked the code, there is only a log warning after MQTT connection lost (https://github.com/gost/server/blob/master/mqtt/mqtt.go#L119). Potential fix: call retryConnect(), check retry interval

dschowta commented 6 years ago

I was wrong. It reconnects. But does not subscribe to the topics again

farshidtz commented 6 years ago

I see opts.SetAutoReconnect(true) but because of opts.SetCleanSession(true) the broker removes the subscriptions. CleanSession should either be set to false (which may cause memory issues on the broker) or the client should re-subscribe on Connect.

tebben commented 6 years ago

I will have a look tomorrow.

tebben commented 6 years ago

I made some changes.

Persistence enabled (enabled by default in latest version) It is now possible to have persistence, this is done by setting subscriptionQos to 1 or 2 and persistent to true in config.yaml or using the environment variables GOST_MQTT_SUBSCRIPTIONQOS and GOST_MQTT_PERSISTENT. After GOST loses connection to the broker it will try to reconnect and will receive all messages that were sent to the broker while GOST was disconnected. Persistent=true in combination with qos=0 will not work. Memory isn't a limiting factor, messages are stored in a database by the mosquitto broker until they are send to GOST.

Persistence disabled When config setting subscriptionQos is set to 0 or persistent set to false GOST will resubscribe now after reconnecting to the broker, messages send to the broker while GOST was disconnected are lost since persistence is disabled.