Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MF-28 - enabled messages paho persistence #27

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

pricelessrabbit
Copy link
Contributor

@pricelessrabbit pricelessrabbit commented Nov 8, 2020

This PR enables export service to persist pending messages in the filesystem instead of in-memory.
In this way there is no data loss if export service fails or it is restarted when there are buffered messages.
However, there is still a flaw when the service is started when MQTT broker is unreachable (this is a known limitation of paho lib). See the issue i opened for details

  • enabled persistent session to avoid paho to discard pending message if service restarted
  • added option to use the paho filesystem storage
  • updated readme

Signed-off-by: PricelessRabbit [email protected]

@pricelessrabbit pricelessrabbit force-pushed the paho-file-storage branch 3 times, most recently from cf42858 to 72c98c0 Compare November 8, 2020 09:16
* enabled persistent session to avoid paho to discard pending message  if service restarted
* updated readme

Signed-off-by: PricelessRabbit <[email protected]>
@mteodor mteodor changed the title * enabled messages paho persistence MF-28 - enabled messages paho persistence Nov 10, 2020
mteodor
mteodor previously approved these changes Nov 10, 2020
@@ -162,11 +162,16 @@ func (e *exporter) mqttConnect(conf config.Config, logger logger.Logger) (mqtt.C
opts := mqtt.NewClientOptions().
AddBroker(conf.MQTT.Host).
SetClientID(e.id).
SetCleanSession(true).
SetCleanSession(false).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be optional, so that when started for the first time it can start with the new session. Should be added to ENV vars.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added variable to the env in new commit

- automatically put clean session to false if file message persistence enabled
- updated doc

Signed-off-by: PricelessRabbit <[email protected]>
if conf.MQTT.Persist {
store := mqtt.NewFileStore(conf.MQTT.PersistDir)
opts.SetStore(store)
//disable clean session because paho deletes stored messages when restarts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments start with the capital letter. Also, add one space after //.

store := mqtt.NewFileStore(conf.MQTT.PersistDir)
opts.SetStore(store)
//disable clean session because paho deletes stored messages when restarts
opts.SetCleanSession(false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want to make this configurable?

Copy link
Contributor Author

@pricelessrabbit pricelessrabbit Nov 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if user set persistent = true but clean session = true, when service restarts messages are lost.
so i make it configurable (clean_session) in the config, but if user sets persist = true, the clean session is set accordingly.

I can change implementation and make the settings completely independent, but in that case user have to manually set clean_session = false when he wants to persist messages in fs

Signed-off-by: PricelessRabbit <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants