mirror of
https://github.com/qicosmos/rest_rpc.git
synced 2026-08-29 16:40:48 +08:00
improve publish interface, support publish struct
This commit is contained in:
+33
-26
@@ -394,6 +394,12 @@ void test_sub1() {
|
||||
});
|
||||
|
||||
client.subscribe("key", "unique_token", [](string_view data) {
|
||||
msgpack_codec codec;
|
||||
person p = codec.unpack<person>(data.data(), data.size());
|
||||
std::cout << p.name << "\n";
|
||||
});
|
||||
|
||||
client.subscribe("key1", "unique_token", [](string_view data) {
|
||||
std::cout << data << "\n";
|
||||
});
|
||||
|
||||
@@ -403,33 +409,34 @@ void test_sub1() {
|
||||
return;
|
||||
}
|
||||
|
||||
client1.publish("key", "hello subscriber");
|
||||
client1.publish_by_token("key", "sub_key", "ok");
|
||||
|
||||
std::thread thd([&client1] {
|
||||
while (true) {
|
||||
try {
|
||||
client1.publish("key", "hello subscriber");
|
||||
client1.publish_by_token("key", "unique_token", "ok");
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
std::cout << ex.what() << "\n";
|
||||
}
|
||||
}
|
||||
});
|
||||
//person p{10, "jack", 21};
|
||||
//client1.publish("key", "hello subscriber");
|
||||
//client1.publish_by_token("key", "sub_key", p);
|
||||
//
|
||||
//std::thread thd([&client1, p] {
|
||||
// while (true) {
|
||||
// try {
|
||||
// client1.publish("key", "hello subscriber");
|
||||
// client1.publish_by_token("key", "unique_token", p);
|
||||
// std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
// }
|
||||
// catch (const std::exception& ex) {
|
||||
// std::cout << ex.what() << "\n";
|
||||
// }
|
||||
// }
|
||||
//});
|
||||
|
||||
std::thread thd1([&client1] {
|
||||
while (true) {
|
||||
try {
|
||||
int r = client1.call<int>("add", 2, 3);
|
||||
std::cout << "add result: " << r << "\n";
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
std::cout << ex.what() << "\n";
|
||||
}
|
||||
}
|
||||
});
|
||||
//std::thread thd1([&client1] {
|
||||
// while (true) {
|
||||
// try {
|
||||
// int r = client1.call<int>("add", 2, 3);
|
||||
// std::cout << "add result: " << r << "\n";
|
||||
// }
|
||||
// catch (const std::exception& ex) {
|
||||
// std::cout << ex.what() << "\n";
|
||||
// }
|
||||
// }
|
||||
//});
|
||||
|
||||
std::string str;
|
||||
std::cin >> str;
|
||||
|
||||
Reference in New Issue
Block a user