Commit 502468eb authored by Michael Ott's avatar Michael Ott

Provide parameter -q to specify MQTT QoS

parent c338b12f
......@@ -63,6 +63,7 @@ void usage() {
std::cout << "Options:" << std::endl;
std::cout << " -b<hosts> List of MQTT brokers [default: localhost:1883]" << std::endl;
std::cout << " -q<qos> MQTT QoS to use [default: 0]" << std::endl;
std::cout << " -c<hosts> List of Cassandra hosts [default: none]" << std::endl;
std::cout << " -u<username> Cassandra username [default: none]" << std::endl;
std::cout << " -p<password> Cassandra password [default: none]" << std::endl;
......@@ -171,10 +172,11 @@ int main(int argc, char** argv) {
int port;
std::string nodelist="", jobId="", userId="";
std::string substitution="";
int qos = 0;
uint64_t ts=0;
// Defining options
const char *opts = "b:c:u:p:n:t:j:i:s:h";
const char *opts = "b:q:c:u:p:n:t:j:i:s:h";
char ret;
while ((ret = getopt(argc, argv, opts))!=-1) {
......@@ -204,6 +206,9 @@ int main(int argc, char** argv) {
splitHostList(optarg, hostList);
break;
}
case 'q':
qos = atoi(optarg);
break;
case 'c':
cassandra = true;
splitHostList(optarg, hostList);
......@@ -291,7 +296,7 @@ int main(int argc, char** argv) {
std::cerr << "Could not connect to MQTT broker " << host << ":" << port << std::endl;
return 1;
}
std::cout << "Connected to MQTT broker " << host << ":" << port << std::endl;
std::cout << "Connected to MQTT broker " << host << ":" << port << ", using QoS " << qos << std::endl;
}
//collect job data
......@@ -408,7 +413,7 @@ int main(int argc, char** argv) {
mosquitto_publish_callback_set(_mosq, publishCallback);
uint64_t startTs = getTimestamp();
//send it to broker
if (mosquitto_publish(_mosq, &msgId, topic.c_str(), payload.length(), payload.c_str(), 1, false) != MOSQ_ERR_SUCCESS) {
if (mosquitto_publish(_mosq, &msgId, topic.c_str(), payload.length(), payload.c_str(), qos, false) != MOSQ_ERR_SUCCESS) {
std::cerr << "Broker not reachable! Job data was not published." << std::endl;
retCode = 1;
goto exit;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment