Open chenzl-123 opened 2 years ago
void test_sub1() { rpc_client client; client.enable_auto_reconnect(); client.enable_auto_heartbeat(); bool r = client.connect("127.0.0.1", 9000); if (!r) { return; }
client.subscribe( "key", "048a796c8a3c6a6b7bd1223bf2c8cee05232e927b521984ba417cb2fca6df9d1", [](string_view data) { msgpack_codec codec; person p = codec.unpack(data.data(), data.size()); std::cout << p.name << "\n"; test_performance1(); });
}
使用测试程序test_performance1();会报timeout or deferred
会这样,因为subscribe回调是io线程,在io线程中发起一个新的io操作,就会造成循环等待,sub等pub,pub等sub,不要阻塞io线程,可以用在另外一个独立线程中去pub。
void test_sub1() { rpc_client client; client.enable_auto_reconnect(); client.enable_auto_heartbeat(); bool r = client.connect("127.0.0.1", 9000); if (!r) { return; }
client.subscribe( "key", "048a796c8a3c6a6b7bd1223bf2c8cee05232e927b521984ba417cb2fca6df9d1", [](string_view data) { msgpack_codec codec; person p = codec.unpack(data.data(), data.size());
std::cout << p.name << "\n";
test_performance1();
});
}
使用测试程序test_performance1();会报timeout or deferred