【发布时间】:2021-11-27 15:31:00
【问题描述】:
我正在使用我在this example 之后实现的 MongoDB Reactive Streams Java API,但我遇到了一个严重的问题:有时,当我尝试查询集合时,await 方法不起作用,它会一直挂起,直到超时。
onSubscribe 方法被正确调用,但是onNext、onError 和 onComplete 都没有被调用。
似乎没有导致此问题的特定情况。
这是我的代码
MongoDatabase database = MongoDBConnector.getClient().getDatabase("myDb");
MongoCollection<Document> collection = database.getCollection("myCollection");
FindPublisher<Document> finder = collection.find(Filters.exists("myField"));
SettingSubscriber tagSub = new SettingSubscriber(finder);
//SettingsSubscriber is a subclass of ObservableSubscriber which calls publisher.subscribe(this)
tagSub.await(); //this is where it hangs
return tagSub.getWrappedData();
【问题讨论】:
-
publisher#subscribe(subscriber),不见了。请参阅Quick Tour - MongoDB Reactive Streams Java Driver。另请参阅org.reactivestreams.Publisher's subscribe()。 -
@prasad_ 实际上它就在那里(参见第 5 行代码的注释)。另外,正如我所说,
onSubscribe总是被调用。 -
@gscaparrotti
myCollection集合中有多少文档?myField的存在检查将执行完整的集合扫描。如果集合中有很多记录,则查询可能超时 -
文档不足100个,超时1分钟,所以我觉得不是这样。
标签: java mongodb reactive-streams