Skip to content

Commit bb70677

Browse files
authored
Use newer MQTT on-message callback in samples (#238)
Also update dependencies
1 parent 8b095fd commit bb70677

File tree

4 files changed

+33
-10
lines changed

4 files changed

+33
-10
lines changed

samples/greengrass/basic_discovery/main.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,12 @@ int main(int argc, char *argv[])
237237

238238
if (mode == "both" || mode == "subscribe")
239239
{
240-
auto onPublish = [&](Mqtt::MqttConnection & /*connection*/,
240+
auto onMessage = [&](Mqtt::MqttConnection & /*connection*/,
241241
const String &receivedOnTopic,
242-
const ByteBuf &payload) {
242+
const ByteBuf &payload,
243+
bool /*dup*/,
244+
Mqtt::QOS /*qos*/,
245+
bool /*retain*/) {
243246
fprintf(stdout, "Publish received on topic %s\n", receivedOnTopic.c_str());
244247
fprintf(stdout, "Message: \n");
245248
fwrite(payload.buffer, 1, payload.len, stdout);
@@ -267,7 +270,7 @@ int main(int argc, char *argv[])
267270
}
268271
};
269272

270-
conn.Subscribe(topic.c_str(), AWS_MQTT_QOS_AT_MOST_ONCE, onPublish, onSubAck);
273+
conn.Subscribe(topic.c_str(), AWS_MQTT_QOS_AT_MOST_ONCE, onMessage, onSubAck);
271274
}
272275
else
273276
{

samples/mqtt/basic_pub_sub/main.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,12 @@ int main(int argc, char *argv[])
456456
connection->OnConnectionInterrupted = std::move(onInterrupted);
457457
connection->OnConnectionResumed = std::move(onResumed);
458458

459-
connection->SetOnMessageHandler([](Mqtt::MqttConnection &, const String &topic, const ByteBuf &payload) {
459+
connection->SetOnMessageHandler([](Mqtt::MqttConnection &,
460+
const String &topic,
461+
const ByteBuf &payload,
462+
bool /*dup*/,
463+
Mqtt::QOS /*qos*/,
464+
bool /*retain*/) {
460465
fprintf(stdout, "Generic Publish received on topic %s, payload:\n", topic.c_str());
461466
fwrite(payload.buffer, 1, payload.len, stdout);
462467
fprintf(stdout, "\n");
@@ -479,7 +484,12 @@ int main(int argc, char *argv[])
479484
/*
480485
* This is invoked upon the receipt of a Publish on a subscribed topic.
481486
*/
482-
auto onPublish = [&](Mqtt::MqttConnection &, const String &topic, const ByteBuf &byteBuf) {
487+
auto onMessage = [&](Mqtt::MqttConnection &,
488+
const String &topic,
489+
const ByteBuf &byteBuf,
490+
bool /*dup*/,
491+
Mqtt::QOS /*qos*/,
492+
bool /*retain*/) {
483493
fprintf(stdout, "Publish received on topic %s\n", topic.c_str());
484494
fprintf(stdout, "\n Message:\n");
485495
fwrite(byteBuf.buffer, 1, byteBuf.len, stdout);
@@ -512,7 +522,7 @@ int main(int argc, char *argv[])
512522
subscribeFinishedPromise.set_value();
513523
};
514524

515-
connection->Subscribe(topic.c_str(), AWS_MQTT_QOS_AT_LEAST_ONCE, onPublish, onSubAck);
525+
connection->Subscribe(topic.c_str(), AWS_MQTT_QOS_AT_LEAST_ONCE, onMessage, onSubAck);
516526
subscribeFinishedPromise.get_future().wait();
517527

518528
while (true)

samples/mqtt/raw_pub_sub/main.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,12 @@ int main(int argc, char *argv[])
329329
connection->OnConnectionInterrupted = std::move(onInterrupted);
330330
connection->OnConnectionResumed = std::move(onResumed);
331331

332-
connection->SetOnMessageHandler([](Mqtt::MqttConnection &, const String &topic, const ByteBuf &payload) {
332+
connection->SetOnMessageHandler([](Mqtt::MqttConnection &,
333+
const String &topic,
334+
const ByteBuf &payload,
335+
bool /*dup*/,
336+
Mqtt::QOS /*qos*/,
337+
bool /*retain*/) {
333338
fprintf(stdout, "Generic Publish received on topic %s, payload:\n", topic.c_str());
334339
fwrite(payload.buffer, 1, payload.len, stdout);
335340
fprintf(stdout, "\n");
@@ -352,7 +357,12 @@ int main(int argc, char *argv[])
352357
/*
353358
* This is invoked upon the receipt of a Publish on a subscribed topic.
354359
*/
355-
auto onPublish = [&](Mqtt::MqttConnection &, const String &topic, const ByteBuf &byteBuf) {
360+
auto onMessage = [&](Mqtt::MqttConnection &,
361+
const String &topic,
362+
const ByteBuf &byteBuf,
363+
bool /*dup*/,
364+
Mqtt::QOS /*qos*/,
365+
bool /*retain*/) {
356366
fprintf(stdout, "Publish received on topic %s\n", topic.c_str());
357367
fprintf(stdout, "\n Message:\n");
358368
fwrite(byteBuf.buffer, 1, byteBuf.len, stdout);
@@ -385,7 +395,7 @@ int main(int argc, char *argv[])
385395
subscribeFinishedPromise.set_value();
386396
};
387397

388-
connection->Subscribe(topic.c_str(), AWS_MQTT_QOS_AT_LEAST_ONCE, onPublish, onSubAck);
398+
connection->Subscribe(topic.c_str(), AWS_MQTT_QOS_AT_LEAST_ONCE, onMessage, onSubAck);
389399
subscribeFinishedPromise.get_future().wait();
390400

391401
while (true)

0 commit comments

Comments
 (0)