spring-webflux 相关问题

Spring Framework 5包含一个新的spring-webflux模块。该模块包含对被动HTTP和WebSocket客户端以及被动服务器Web应用程序的支持,包括REST,HTML浏览器和WebSocket样式交互.WebFlux可以在Servlet容器上运行,支持Servlet 3.1非阻塞IO API以及其他异步运行时,如Netty和Undertow。

无法在 Spring Boot 中使用 WebFlux 使用 H2 和 R2DBC 创建 ConnectionFactory 错误

我使用 WebFlux 反应式模块、H2 内存数据库和 R2DBC 反应式驱动程序创建了一个 Java Spring Boot 服务。 当我运行该服务时,它失败并显示“无法创建

回答 5 投票 0

当 Mono.zip 中发生错误时,Spring WebFlux 返回响应,但继续处理它们

我有一个调用其他远程服务的 REST 服务(我们称之为“主服务”)。出于性能目的,当其中一个远程调用抛出错误时,我需要主服务立即应答;布...

回答 1 投票 0

使用 ParameterizedTypeReference 的通用类型 WebClient

我调用一个 Web 服务,该服务根据我作为参数传递的字符串别名返回以下 Json, 如果别名是 isActive, 然后 json 响应 = {isActive=true} 如果别名是 RolesAlias, ...

回答 1 投票 0

使用ReactiveSecurityContextHolder设置后Spring WebFlux安全上下文为空

我正在使用 Spring Boot 和 Spring Security 开发反应式应用程序,特别是处理 Kafka 消费者中的身份验证。尽管使用

回答 1 投票 0

Spring Boot graphQl 自动配置无法在应用程序启动时实例化 graphQlSource

我有一个使用 spring-webflux 和 spring-graphql 的 Spring Boot 应用程序。启动时,自动配置机制无法实例化 graphQlSource bean,因为它无法运行工厂方法...

回答 1 投票 0

Project Reactor 中 doOnNext 的“即发即忘”操作

我有一个 Flux 流。对于处理的每个元素,我希望触发一个异步/非阻塞操作。例如,从数据库更新返回 Mono 的方法。 我想要...

回答 2 投票 0

带有 netty 服务器和 swagger-ui 的反应式 springboot

我有一个在 netty 服务器上运行的反应式 spring-boot 应用程序,其中 springboot 版本为 3.2.2 和 Java 17。当我添加依赖项时 org.springdoc 我有一个在 netty 服务器上运行的反应式 spring-boot 应用程序,其中 springboot 版本为 3.2.2 和 Java 17。当我添加依赖项时 <dependency> <groupId>org.springdoc</groupId> <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId> <version>2.3.0</version> </dependency> /swagger-ui/index.html 或 /swagger-ui.html 路由不返回任何内容。 我尝试将其向下打开以打开 Swagger 2,但没有成功。 在高处,感觉太愚蠢了,我没有注意到有一个单独的通量库 正如 Alex 指出的,解决这个问题的方法是改变依赖关系。 <dependency> <groupId>org.springdoc</groupId> <artifactId>springdoc-openapi-starter-webflux-ui</artifactId> <version>LATEST_RELEASE_VERION</version> </dependency>

回答 1 投票 0

如何在MongoDB中通过UUID查找

我有一个 Spring Boot 项目,我使用 MongoDb-reactive 和 webflux。 我有一些实体,其 UUID 作为 _id。我正在尝试编写一个接受 UUID 并返回匹配对象的端点。

回答 1 投票 0

如何修改Spring Boot反应式oauth2授权请求的正文

当我使用下面定义的 WebClient 时,将创建并发送授权请求。 如何修改 Spring Boot 发送的授权 POST 请求以获取不记名令牌?我需要添加一些...

回答 2 投票 0

WebFlux 应用程序中的 WebFilter

我有一个使用 Spring Boot 2.0.0.M5/2.0.0.BUILD-SNAPSHOT 的 Spring Boot WebFlux 应用程序。 我需要将跟踪 ID 添加到所有日志中。 为了让它在 WebFlux 应用程序中工作,我

回答 4 投票 0

如何在使用 Spring boot webclient 调用第三方 api 时阻止() Reactor Http 线程?

我正在编写一个通用方法来从我的微服务调用第三方 API。 private R processRequest(String url, Class type, HttpEntity requestEntity, HttpMethod meth... 我正在编写一个通用方法来从我的微服务调用第三方 API。 private <R,P> R processRequest(String url, Class<R> type, HttpEntity<P> requestEntity, HttpMethod method) { HttpHeaders httpHeaders = requestEntity.getHeaders(); Mono<R> result = getResult(method, url, httpHeaders, type); R responseBody = result.block(); return responseBody; } private <R> Mono<R> getResult(HttpMethod method, String url, HttpHeaders httpHeaders, Class<R> type) { return webClient.method(method) .uri(url) .accept(MediaType.ALL) .contentType(MediaType.APPLICATION_JSON) .headers(headers -> headers.putAll(httpHeaders)) .retrieve() .onStatus(HttpStatusCode::is4xxClientError, clientResponse -> Mono.error(new RuntimeException("Client error"))) .onStatus(HttpStatusCode::is5xxServerError, clientResponse -> Mono.error(new RuntimeException("Server error"))) .bodyToMono(type); } 但是,当我调用 processRequest() 方法时,我收到以下错误。 java.lang.IllegalStateException: block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-http-nio-3 任何人都可以帮忙解决这个问题吗? 技术堆栈: 爪哇:17 spring-boot-starter-parent :3.1.1 spring-boot-starter-webflux:3.1.1 P.S.我需要一个阻塞调用,并且我知道在反应式代码中使用阻塞操作并不好 Reactor 是一个非阻塞库,所以在 Spring http 线程池中阻塞它的事件是不正确的用法(PS 但一般情况下可能会有一些偶尔需要的情况,reactor api 非常有用); 简单来说,可以新建一个业务进程线程池来提交非阻塞的api请求;这是一些代码片段供参考。 @Component public class MyApiClient { private final WebClient webClient; public MyApiClient(WebClient.Builder webClientBuilder) { this.webClient = webClientBuilder.build(); } public <R, P> R processRequest(String url, Class<R> type, HttpEntity<P> requestEntity, HttpMethod method) { HttpHeaders httpHeaders = requestEntity.getHeaders(); Mono<R> result = getResult(method, url, httpHeaders, type); return blockMono(result); } private <R> Mono<R> getResult(HttpMethod method, String url, HttpHeaders httpHeaders, Class<R> type) { return webClient.method(method) .uri(url) .accept(MediaType.ALL) .contentType(MediaType.APPLICATION_JSON) .headers(headers -> headers.putAll(httpHeaders)) .retrieve() .onStatus(HttpStatus::is4xxClientError, clientResponse -> Mono.error(new RuntimeException("Client error"))) .onStatus(HttpStatus::is5xxServerError, clientResponse -> Mono.error(new RuntimeException("Server error"))) .bodyToMono(type); } private <R> R blockMono(Mono<R> mono) { // just init a thread pool , any way you favorite is ok ExecutorService executor = Executors.newSingleThreadExecutor(); try { return executor.submit((Callable<R>) mono::block).get(); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException("Error occurred while blocking Mono", e); } finally { executor.shutdown(); } } } 您处于 Spring 环境中,因此有必要将业务流程线程池初始化为连接到 Spring 的 bean,如下所示。 @Bean public ThreadPoolTaskExecutor taskExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(5); executor.setMaxPoolSize(10); executor.setQueueCapacity(100); executor.setThreadNamePrefix("Bussiness-Pool-"); executor.initialize(); return executor; } 注释 bean 如下或构建默认构造方法以自动装配 @Resource ThreadPoolTaskExecutor executor;

回答 1 投票 0

在 spring-r2dbc 中忽略查询字段

我在 spring webflex 应用程序中使用 spring r2dbc 和 ReactiveCrudRepository 。 我有一个在生成选择查询时需要忽略的字段 (控制器代码中是 r2dbcEntityTempl...

回答 2 投票 0

functionCatalog.lookup(“sendFluxToWeb|sendFluxToKafka”)的问题

我想要实现的目标: 以反应方式将字符串流发送到 webapi 并发送到 kafka。 显示一些代码: 导入 org.springframework.boot.SpringApplication; 导入 org.springframework...

回答 1 投票 0

项目 Reactor 堆栈中的条件行为

我需要创建一个从外部缓存获取数据的方法。如果找到数据,它会进行一些处理,否则它应该进行不同的处理。 该方法应该返回 Mono 单声道

回答 1 投票 0

WebFlux Flux.cache() 缓存发出的数据存储多长时间

上下文: 我有一个有限的 Flux,它是 Rest API 调用的来源,并且该通量位于对我的 Spring Boot 应用程序进行的主 REST API 调用的范围内,该应用程序返回 Mono 并响应。我愿意...

回答 1 投票 0

API调用错误:5000ms内未观察到任何项目或终端信号(且未配置回退)

我们正在使用两个完全用Spring WebFlux编写的服务,当从服务A调用/调用服务B时,我们看到下面的错误,我们无法进一步调试......

回答 3 投票 0

如何使用 r2dbc @Query 正确编写三个值选项的查询: true、false、null ? (postgresql)

我正在尝试发出请求以从数据库获取数据 参数中包含三个选项的布尔值: false - 显示带有 false 的实体 true - 显示带有 true 的实体 null - 任何操作...

回答 2 投票 0

微服务 REST 调用和数据库事务

最近我遇到了以下情况。 我的两个服务正在使用 REST 调用相互调用。 我们将其命名为:ServiceA 和 ServiceB。 场景如下: ServiceA 接收来自...的一些输入

回答 1 投票 0

如何将 Mono 变成真正的异步(非反应式!)方法调用?

我有一个方法 @服务 公共类我的服务{ 公共 Mono processData() { ... // 非常长的反应操作 } } 在正常的程序流程中,我调用这个方法

回答 2 投票 0

Spring WebClient如何减少DNS缓存TTL?

我正在使用 WebClient(来自 Spring-Weblux),目前它缓存 DNS 30 分钟。 我没有看到任何关于如何减少 DNS 缓存的信息。 我怎样才能把它减少到30秒? HttpClient 客户端 = HttpCli...

回答 2 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.