- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个服务将数据流式传输到第二个服务,该服务接收对象流并将它们保存到我的 MongoDB。
在我从流服务获得的 Flux 对象上的 subscribe 函数中,我使用了 ReactiveMongoRepository 接口(interface)中的 save 方法。
当我尝试使用 block 函数并获取数据时,出现以下错误:
2019-10-11 13:30:38.559 INFO 19584 --- [localhost:27017] org.mongodb.driver.connection : Opened connection [connectionId{localValue:1, serverValue:25}] to localhost:27017
2019-10-11 13:30:38.566 INFO 19584 --- [localhost:27017] org.mongodb.driver.cluster : Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[4, 0, 1]}, minWireVersion=0, maxWireVersion=7, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=6218300}
2019-10-11 13:30:39.158 INFO 19584 --- [ctor-http-nio-4] quote-monitor-service : onNext(Quote(id=null, ticker=AAPL, price=164.8, instant=2019-10-11T10:30:38.800Z))
2019-10-11 13:30:39.411 INFO 19584 --- [ctor-http-nio-4] quote-monitor-service : cancel()
2019-10-11 13:30:39.429 INFO 19584 --- [ntLoopGroup-2-2] org.mongodb.driver.connection : Opened connection [connectionId{localValue:3, serverValue:26}] to localhost:27017
2019-10-11 13:30:39.437 WARN 19584 --- [ctor-http-nio-4] io.netty.util.ReferenceCountUtil : Failed to release a message: DefaultHttpContent(data: PooledSlicedByteBuf(freed), decoderResult: success)
io.netty.util.IllegalReferenceCountException: refCnt: 0, decrement: 1
at io.netty.util.internal.ReferenceCountUpdater.toLiveRealRefCnt(ReferenceCountUpdater.java:74) ~[netty-common-4.1.39.Final.jar:4.1.39.Final]
at io.netty.util.internal.ReferenceCountUpdater.release(ReferenceCountUpdater.java:138) ~[netty-common-4.1.39.Final.jar:4.1.39.Final]
at
reactor.core.Exceptions$ErrorCallbackNotImplemented: java.lang.IllegalStateException: block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-http-nio-4
Caused by: java.lang.IllegalStateException: block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-http-nio-4
at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:77) ~[reactor-core-3.2.12.RELEASE.jar:3.2.12.RELEASE]
at reactor.core.publisher.Mono.block(Mono.java:1494) ~[reactor-core-3.2.12.RELEASE.jar:3.2.12.RELEASE]
at
stockQuoteClient.getQuoteStream()
.log("quote-monitor-service")
.subscribe(quote -> {
Mono<Quote> savedQuote = quoteRepository.save(quote);
System.out.println("I saved a quote! Id: " +savedQuote.block().getId());
});
stockQuoteClient.getQuoteStream()
.log("quote-monitor-service")
.subscribe(quote -> {
Mono<Quote> savedQuote = quoteRepository.insert(quote);
savedQuote.subscribe(result ->
System.out.println("I saved a quote! Id :: " + result.getId()));
});
最佳答案
阻塞是不好的,因为它占用了一个等待响应的线程。在一个只有很少线程可供使用的响应式(Reactive)框架中,这是非常糟糕的,并且被设计成它们都不应该被不必要地阻塞。
这正是响应式框架旨在避免的事情,所以在这种情况下,它只会阻止你这样做:
block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-http-nio-4
savedQuote.subscribe()
的 lambda 被执行,将你的结果打印到控制台。)
doOnNext()
对于副作用(例如打印出一个值):
stockQuoteClient.getQuoteStream()
.log("quote-monitor-service")
.flatMap(quoteRepository::insert)
.doOnNext(result -> System.out.println("I saved a quote! Id :: " + result.getId())))
.subscribe();
关于mongodb - 在 Mono 对象上执行 block() 时出现异常我从 ReactiveMongoRepository 对象返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58339681/
我认为这个问题可能与我的Mongo Document Koltin Data类有关,但是对于我们的业务案例,我们需要允许用户添加任何JSON字段来描述其RF数据集。 扩展BasicDBObject是我
我知道分页有点违背 react 性原则,但由于要求我必须以某种方式让它工作。我正在使用 Spring Data 2.1.6,但我无法升级所以 ReactiveQuerydslSpecification
我有一个扩展了 ReactiveMongoRepository 的 MovieRepository。我想以 react 方式保存单个 POJO。但是 ReactiveMongoRepository 没
我有一个扩展了 ReactiveMongoRepository 的 MovieRepository。我想以 react 方式保存单个 POJO。但是 ReactiveMongoRepository 没
我有一个服务将数据流式传输到第二个服务,该服务接收对象流并将它们保存到我的 MongoDB。 在我从流服务获得的 Flux 对象上的 subscribe 函数中,我使用了 ReactiveMongoR
当使用 Spring Data MongoDB 的响应式(Reactive)编程模型时,可以执行如下事务: Mono result = template.inTransaction()
我们正在 Spring 5 Reactive Stack 上开发一个应用程序。为了持久化,我们将 MongoDb 与来自 Spring Data 的 ReactiveMongoRepository (
我是一名优秀的程序员,十分优秀!