title: How to set the configuration properties for Mosquitto in c++?
body: <p>I am writing mosquitto code for consuming the message after subscribing to a particular topic. Now I want to set different configuration for mosquitto like </p>
  
  <pre><code>autosave_interval 100
  persistence true
  persistence_location /var/lib/mosquitto/
  persistence_file mosquitto.db
  </code></pre>
  
  <p>But I have no idea how to set this configuration in c++. I tried to google it but could not found any result. Plz, help. Below is c++ code for mosquito</p>
  
  <p><strong><em>myMosq.h</em></strong></p>
  
  <pre><code>/*
   * myMosq.h
   *
   *  Created on: Jul 28, 2016
   *      Author: nilav
   */
  #include &lt;iostream&gt;
  #ifndef MYMOSQ_H_
  #define MYMOSQ_H_
  
  #include &lt;mosquittopp.h&gt;
  #include &lt;mosquitto.h&gt;
  using namespace std;
  
  class myMosq : public mosqpp::mosquittopp
  {
  private:
   const char     *     host;
   const char    *     id;
   const char    *     topic;
   int                port;
   int                keepalive;
  
   void on_connect(int rc);
   void on_message(const struct mosquitto_message *message);
   void on_disconnect(int rc);
   void on_subscribe(int mid, int qos_count, const int *granted_qos);
   void on_publish(int mid);
   void on_unsubscribe(int mid);
  
  public:
   myMosq(const char *id, const char * _topic, const char *host, int port);
   ~myMosq();
   bool send_message(string responseMessage);
   bool receive_message();
   void writeToDatabase(string query);
  };
  
  #endif
  </code></pre>
  
  <p><strong><em>myMosq.cpp</em></strong></p>
  
  <pre><code>#include &lt;cstdio&gt;
  #include &lt;cstring&gt;
  #include &lt;iostream&gt;
  
  #include "myMosq.h"
  #include &lt;mosquittopp.h&gt;
  #include "Configuration.h"
  #include "Databases.h"
  
  using namespace std;
  
  Configuration configuration;
  
  myMosq::myMosq(const char * _id,const char * _topic, const char * _host, int _port) : mosquittopp(_id)
   {
   mosqpp::lib_init();        // Mandatory initialization for mosquitto library
   this-&gt;keepalive = 60;    // Basic configuration setup for myMosq class
   this-&gt;id = _id;
   this-&gt;port = _port;
   this-&gt;host = _host;
   this-&gt;topic = _topic;
   connect_async(host,     // non blocking connection to broker request
   port,
   keepalive);
   loop_start();            // Start thread managing connection / publish / subscribe
   };
  
  myMosq::~myMosq() {
   loop_stop();            // Kill the thread
   mosqpp::lib_cleanup();    // Mosquitto library cleanup
   }
  
  
  bool myMosq::receive_message()
   {
      int set = subscribe(NULL, configuration.subscriptionTopic.c_str(),2);
      return set;
   }
  
  bool myMosq::send_message(string responseMessage) {
      int ret = publish(NULL,configuration.producerTopic.c_str(),strlen(responseMessage.c_str()),responseMessage.c_str(),1,false);
      return (ret = MOSQ_ERR_SUCCESS);
  }
  
  void myMosq::on_disconnect(int rc) {
   std::cout &lt;&lt; "&gt;&gt; myMosq - disconnection(" &lt;&lt; rc &lt;&lt; ")" &lt;&lt; std::endl;
   }
  
  
  void myMosq::on_connect(int rc)
   {
   if ( rc == 0 ) {
   std::cout &lt;&lt; "&gt;&gt; myMosq - connected with server" &lt;&lt; std::endl;
   } else {
   std::cout &lt;&lt; "&gt;&gt; myMosq - Impossible to connect with server(" &lt;&lt; rc &lt;&lt; ")" &lt;&lt; std::endl;
   }
   }
  
  void myMosq::on_message(const struct mosquitto_message *message) {
  
      char * pchar = (char*)(message-&gt;payload);
      string str(pchar);
      writeToDatabase(str);
  }
  
  void myMosq::on_subscribe(int mid, int qos_count, const int *granted_qos)
  {
      std::cout &lt;&lt; "&gt;&gt; subscription succeeded (" &lt;&lt; mid &lt;&lt; ") " &lt;&lt; std::endl;
  }
  
  void myMosq::on_publish(int mid) {
      std::cout &lt;&lt; "&gt;&gt; myMosq - Message (" &lt;&lt; mid &lt;&lt; ") succeed to be published " &lt;&lt; std::endl;
  }
  
  void myMosq::writeToDatabase(string query) {
  
      Databases* database = new Databases(configuration.db,
              configuration.dbPort, configuration.username, configuration.password,
              configuration.schema);
      database-&gt;writeDatabase(query);
  
      if(database-&gt;responseMessage == "") {
          database-&gt;responseMessage = "SUCCESS";
      }
  
      this-&gt;send_message(database-&gt;responseMessage);
  }
  
  void myMosq::on_unsubscribe(int mid) {
      cout&lt;&lt;"unscubscribed";
  };
  </code></pre>