0

I have subscribed to multiple (around 4) topics using paho.mqtt.

On receiving message from each topic, I want to buffer the message until it reaches some threshold and then later insert bulk messages into MySQL database.I want to gather some 1000 messages and check if the threshold is greater than 1000 and then finally insert into database on certain time interval (for every 1 minute).

For each topic, there is corresponding table in the database. Which callback function Should I use on_message() callback or message_callback_add()? Which is better in such scenario?

hardillb
  • 54,545
  • 11
  • 67
  • 105
user2301
  • 1,857
  • 6
  • 32
  • 63

1 Answers1

2

What does "is better" mean for you?

The callback registered with on_message() will get all messages for all your subscriptions, whereas with message_callback_add you can have different callbacks for each topic that you subscribe to.

Do you need your callbacks to do different things based on the topic name? If not, you use on_message, else you use message_callback_add.

hardillb
  • 54,545
  • 11
  • 67
  • 105
Gambit Support
  • 1,432
  • 1
  • 7
  • 17
  • I want to store the messages into MySQL database for all the subscribed topics. Okay thank you, I will use on_message callback only – user2301 Dec 11 '17 at 14:28