Commit 22c2cd01b98c43b644b1bb8ff22b6e71eb30bf45

Authored by Patric Stout
1 parent 81c47790

fix(example-pubsub): pick example topics a bit better

As the last-will is retained, multiple runs gave different results.
By picking the topics better, this is no longer the case.
Showing 1 changed file with 9 additions and 9 deletions
example/pubsub/main.cpp
... ... @@ -19,37 +19,37 @@ int main()
19 19 client.setPublishQueue(TrueMQTT::Client::PublishQueueType::FIFO, 10);
20 20 client.setErrorCallback([](TrueMQTT::Client::Error error, std::string message)
21 21 { std::cout << "Error " << error << ": " << message << std::endl; });
22   - client.setLastWill("test/lastwill", "example pubsub finished", true);
  22 + client.setLastWill("example/pubsub/lastwill", "example pubsub finished", true);
23 23  
24 24 client.connect();
25 25  
26 26 int stop = 0;
27 27  
28 28 // Subscribe to the topic we will be publishing under in a bit.
29   - client.subscribe("test/test/test", [&stop](const std::string topic, const std::string payload)
  29 + client.subscribe("example/pubsub/test/subtest", [&stop](const std::string topic, const std::string payload)
30 30 {
31 31 std::cout << "Received message on exact topic " << topic << ": " << payload << std::endl;
32 32 stop++; });
33   - client.subscribe("test/test/test", [&stop](const std::string topic, const std::string payload)
  33 + client.subscribe("example/pubsub/test/subtest", [&stop](const std::string topic, const std::string payload)
34 34 {
35 35 std::cout << "Received message on exact topic " << topic << ": " << payload << std::endl;
36 36 stop++; });
37   - client.subscribe("test/+/test", [&stop](const std::string topic, const std::string payload)
  37 + client.subscribe("example/pubsub/+/subtest", [&stop](const std::string topic, const std::string payload)
38 38 {
39 39 std::cout << "Received message on single wildcard topic " << topic << ": " << payload << std::endl;
40 40 stop++; });
41   - client.subscribe("test/#", [&stop](const std::string topic, const std::string payload)
  41 + client.subscribe("example/pubsub/test/#", [&stop](const std::string topic, const std::string payload)
42 42 {
43 43 std::cout << "Received message on multi wildcard topic " << topic << ": " << payload << std::endl;
44 44 stop++; });
45   - client.subscribe("test/test/+", [&stop](const std::string topic, const std::string payload)
  45 + client.subscribe("example/pubsub/test/+", [&stop](const std::string topic, const std::string payload)
46 46 {
47   - /* Never actually called */ });
  47 + /* Never actually called, as we unsubscribe a bit later */ });
48 48  
49   - client.unsubscribe("test/test/+");
  49 + client.unsubscribe("example/pubsub/test/+");
50 50  
51 51 // Publish a message on the same topic as we subscribed too.
52   - client.publish("test/test/test", "Hello World!", false);
  52 + client.publish("example/pubsub/test/subtest", "Hello World!", false);
53 53  
54 54 // Wait till we receive the message back on our subscription.
55 55 while (stop < 4)
... ...