Reactor Netty を使用した Spring Webflux マイクロサービスを使用する私のユース ケースでは、次の依存関係があります。
org.springframework.boot.spring-boot-starter-webflux
(2.0.1.RELEASE)org.springframework.boot.spring-boot-starter-data-mongodb-reactive
(2.0.1.RELEASE)org.projectreactor.reactor-spring
(1.0.1.RELEASE)
非常に特殊なケースでは、Mongo データベースからいくつかの情報を取得し、これを処理して、reactive で送信するクエリ パラメータにする必要がありますWebClient
。WebClient
もUriComponentsBuilder
パブリッシャー (Mono / Flux) も受け入れないため、呼び出しを使用して#block()
結果を受け取りました。
reactor-core
最新 (バージョン 2.0.1.RELEASE) に含まれている(バージョン 0.7.6.RELEASE)以降spring-boot-dependencies
、使用できなくなりました:block()/blockFirst()/blockLast() are blocking, which is not supported in thread xxx
を参照してください -> https://github.com/reactor/reactor-netty/問題/312
私のコードスニペット:
public Mono<FooBar> getFooBar(Foo foo) {
MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
parameters.add("size", foo.getSize());
parameters.addAll("bars", barReactiveCrudRepository.findAllByIdentifierIn(foo.getBarIdentifiers()) // This obviously returns a Flux
.map(Bar::toString)
.collectList()
.block());
String url = UriComponentsBuilder.fromHttpUrl("https://base-url/")
.port(8081)
.path("/foo-bar")
.queryParams(parameters)
.build()
.toString();
return webClient.get()
.uri(url)
.retrieve()
.bodyToMono(FooBar.class);
}
これはspring-boot
バージョン 2.0.0.RELEASE では機能しましたが、バージョン 2.0.1.RELEASE へのアップグレード以降、バージョン 0.7.6.RELEASE へのアップグレード以降reactor-core
は許可されなくなりました。
私が見る唯一の実際の解決策は、ブロック (非反応性) リポジトリ/mongo クライアントも含めることですが、それが推奨されるかどうかはわかりません。助言がありますか?