rest_rpc icon indicating copy to clipboard operation
rest_rpc copied to clipboard

客户端在订阅中调用发布会超时

Open chenzl-123 opened this issue 3 years ago • 1 comments

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

chenzl-123 avatar Jan 25 '22 02:01 chenzl-123

会这样,因为subscribe回调是io线程,在io线程中发起一个新的io操作,就会造成循环等待,sub等pub,pub等sub,不要阻塞io线程,可以用在另外一个独立线程中去pub。

qicosmos avatar Jan 25 '22 03:01 qicosmos