rest_rpc
rest_rpc copied to clipboard
客户端在订阅中调用发布会超时
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
}
使用测试程序test_performance1();会报timeout or deferred
会这样,因为subscribe回调是io线程,在io线程中发起一个新的io操作,就会造成循环等待,sub等pub,pub等sub,不要阻塞io线程,可以用在另外一个独立线程中去pub。