我正在使用 Postgre SQL 来玩 R2DBC。我正在尝试的用例是通过 ID 以及语言、演员和类别获取电影。下面是架构
这是ServiceImpl中对应的一段代码
@Override
public Mono<FilmModel> getById(Long id) {
Mono<Film> filmMono = filmRepository.findById(id).switchIfEmpty(Mono.error(DataFormatException::new)).subscribeOn(Schedulers.boundedElastic());
Flux<Actor> actorFlux = filmMono.flatMapMany(this::getByActorId).subscribeOn(Schedulers.boundedElastic());
Mono<String> language = filmMono.flatMap(film -> languageRepository.findById(film.getLanguageId())).map(Language::getName).subscribeOn(Schedulers.boundedElastic());
Mono<String> category = filmMono.flatMap(film -> filmCategoryRepository
.findFirstByFilmId(film.getFilmId()))
.flatMap(filmCategory -> categoryRepository.findById(filmCategory.getCategoryId()))
.map(Category::getName).subscribeOn(Schedulers.boundedElastic());
return Mono.zip(filmMono, actorFlux.collectList(), language, category)
.map(tuple -> {
FilmModel filmModel = GenericMapper.INSTANCE.filmToFilmModel(tuple.getT1());
List<ActorModel> actors = tuple
.getT2()
.stream()
.map(act -> GenericMapper.INSTANCE.actorToActorModel(act))
.collect(Collectors.toList());
filmModel.setActorModelList(actors);
filmModel.setLanguage(tuple.getT3());
filmModel.setCategory(tuple.getT4());
return filmModel;
});
}
Run Code Online (Sandbox Code Playgroud)
日志显示 4 次调用拍摄
2021-12-16 21:21:20.026 DEBUG 32493 --- [ctor-tcp-nio-10] o.s.r2dbc.core.DefaultDatabaseClient : Executing …Run Code Online (Sandbox Code Playgroud) project-reactor spring-webflux spring-data-r2dbc r2dbc r2dbc-postgresql
我想了解Netty的频道选项"WRITE_SPIN_COUNT"的用法.将此值设置为高于或低于默认值(16)的影响是什么.应该这样设置.?这是我从Netty文档中得到的,但不清楚为什么以及何时应该设置此值:http://netty.io/4.0/api/io/netty/channel/DefaultChannelConfig.html#getWriteSpinCount() 按照它说的文档:返回写操作的最大循环计数,直到WritableByteChannel.write(ByteBuffer)返回非零值.它类似于自旋锁用于并发编程的内容.它根据运行JVM的平台提高内存利用率和写入吞吐量.默认值为16.