我有一个针对.Net 4.5.2的多项目Visual Studio解决方案.在其中一个项目(WPF应用程序)中,我使用nuget添加System.Reactive版本3.0.1000.0包,然后添加ReactiveUI 7.0.0.0包.
在WPF应用程序使用的另一个项目库中,我只添加了System.Reactive版本3.0.1000.0包.
ReactiveUI包似乎依赖于一组旧的反应包(RX-Core2.2.5等).我可以告诉你,因为WPF应用程序项目文件中的HintPaths指向诸如packages\Rx-Core.2.2.5\lib \net45\System.Reactive.Core.dll之类的位置
当我构建并运行应用程序时,我得到一个FileLoadException,因为至少有一个项目试图使用错误的dll版本.以下是典型的....
System.IO.FileLoadException occurred
HResult=0x80131040
Message=Could not load file or assembly 'System.Reactive.Linq, Version=3.0.1000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Run Code Online (Sandbox Code Playgroud)
我可以通过将解决方案中的所有System.Reactive软件包降级到2.2.5来解决这个问题,但这似乎是一个非常旧的版本(2014).
为什么ReactiveUI会依赖System.Reactive的v2.2.5?有没有办法改变这种行为,以便我可以在整个解决方案中使用最新版本的System.Reactive?
现在有两种方法可以在Spring 5中公开http端点.
控制器:通过制作休息控制器.
@RestController
@RequestMapping("persons")
public class PersonController {
@Autowired
private PersonRepo repo;
@GetMapping("/{id}")
public Mono<Person> personById(@PathVariable String id){
retrun repo.findById(id);
}
}
Run Code Online (Sandbox Code Playgroud)路由器:通过路由器.例如:
@Bean
public RouterFunction<ServerResponse> personRoute(PersonRepo repo) {
return route(GET("/persons/{id}"), req -> Mono.justOrEmpty(req.pathVariable("id"))
.flatMap(repo::getById)
.flatMap(p -> ok().syncBody(p))
.switchIfEmpty(notFound().build()));
}
Run Code Online (Sandbox Code Playgroud)使用任何一种方法有任何性能差异吗?从头开始编写应用程序时,我应该使用哪一个.
我在面板中有一些图。我想将它们更改为tabsetpanel
窗口宽度较小时。有什么方法可以确定浏览器的窗口宽度。比如下面的例子,当窗口宽度足够大时,如何uiOutput
从切换plotPanel1
到。plotPanel2
library(ggplot2)
ui <- fluidPage(
title = "TestApp",
h1("Test Application"),
sidebarLayout(
sidebarPanel(
sliderInput("bins", "Bins", 2, 20, 1, value = 10)
),
mainPanel(
fluidRow(
uiOutput("plotPanel1")
)
)
)
)
server <- function(input, output, session){
output$plot1 <- renderPlot({
mdl <- lm(mpg ~ ., data = mtcars)
ggplot(mdl, aes(.resid)) + geom_histogram(bins = input$bins)
}, res = 110)
output$plot2 <- renderPlot({
mdl <- lm(UrbanPop ~ ., data = USArrests)
ggplot(mdl, aes(.resid)) + geom_histogram(bins = input$bins)
}, res …
Run Code Online (Sandbox Code Playgroud) 我有一个反应形式,在负载时不需要任何字段.如果选择了一个选项,将其他表单元素添加到formGroup中,则所有新显示的字段都是必需的.如果昵称字段被隐藏,那么您应该能够提交表格.如果显示昵称,则需要昵称字段,并且在昵称字段已满之前禁用提交按钮.这是我想要做的一个例子.
我的问题是,一旦显示/隐藏表单元素,如何启用/禁用验证?
App.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { HelloComponent } from './hello.component';
@NgModule({
imports: [ BrowserModule, FormsModule, ReactiveFormsModule ],
declarations: [ AppComponent, HelloComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)
App.component.ts
import { Component, OnInit } from '@angular/core';
import { Validators, FormControl, FormGroup, FormBuilder } from '@angular/forms';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ …
Run Code Online (Sandbox Code Playgroud) 为了使用 LDAP 保护 Reactive Spring Boot 应用程序,需要进行哪些自定义?到目前为止,我看到的示例都是基于 Spring MVC 的,而保护 WebFlux 的示例仅显示了一个带有内存映射的简单反应式示例。
我是春季反应新手。
我正在尝试使用邮递员从服务器获取请求信息。
首先,邮递员使用 post 方法向服务器发送信息。其次,我们一直在使用相关代码在服务器端工作并获取请求信息。
在下面的代码片段中
不知道能不能拿到ServerRequest函数的JSONObject。
邮递员身体(应用程序/ json)
{
"name": "aaaa",
"name_order": ["aa", "bb", "cc"],
"type": "12",
"query": ""
}
Run Code Online (Sandbox Code Playgroud)
java (RouterFunction)
import com.ntels.io.input.handler.RestInHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.config.EnableWebFlux;
import org.springframework.web.reactive.config.WebFluxConfigurer;
import org.springframework.web.reactive.function.server.*;
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RequestPredicates.POST;
import static org.springframework.web.reactive.function.server.RequestPredicates.PUT;
import static org.springframework.web.reactive.function.server.RequestPredicates.DELETE;
@Configuration
@EnableWebFlux
public class RestConfig implements WebFluxConfigurer {
@Bean
public RouterFunction<ServerResponse> routes(RestInHandler restInHandler){
return RouterFunctions.route(POST("/input/event").
and(RequestPredicates.accept(MediaType.APPLICATION_JSON)), restInHandler::toRESTInVerticle);
}
}
Run Code Online (Sandbox Code Playgroud)
java(处理程序)
public Mono<ServerResponse> toRESTInVerticle(ServerRequest serverRequest) {
String serverRequestUrl = serverRequest.uri().toString();
System.out.println("RestInHandler test …
Run Code Online (Sandbox Code Playgroud) 我有一个简单的问题,是否可以使用 Spring Boot Data r2dbc for MySQL 或其他数据库自动生成表?在 JPA 中,我添加了 spring.jpa.hibernate.ddl-auto=update 并创建了表
这是我的pom:
<dependencies>
<dependency>
<groupId>org.springframework.boot.experimental</groupId>
<artifactId>spring-boot-starter-data-r2dbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>dev.miku</groupId>
<artifactId>r2dbc-mysql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot.experimental</groupId>
<artifactId>spring-boot-test-autoconfigure-r2dbc</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.43.Final</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud) 我正在使用 Spring WebClient 调用休息服务。如下所述的 post 调用代码。
Mono<ClientResponse> response = client.post()
.uri(uriBuilder -> uriBuilder.build())
.headers(httpHeaders -> httpHeaders.setAll(getHeaders()))
.body(BodyInserters.fromPublisher(Mono.just(message), String.class))
.exchange();
response.subscribe(clientResponse -> {
System.out.println(clientResponse.statusCode());
});
Run Code Online (Sandbox Code Playgroud)
在连续发布一段时间后(在 5 分钟内发布 2-3 百万个请求后),我收到以下异常。
[ parallel-3] r.c.s.Schedulers : Scheduler worker in group main failed with an uncaught exception
reactor.core.Exceptions$ErrorCallbackNotImplemented: reactor.netty.internal.shaded.reactor.pool.PoolAcquireTimeoutException: Pool#acquire(Duration) has been pending for more than the configured timeout of 45000ms
Caused by: reactor.netty.internal.shaded.reactor.pool.PoolAcquireTimeoutException: Pool#acquire(Duration) has been pending for more than the configured timeout of 45000ms
at reactor.netty.internal.shaded.reactor.pool.AbstractPool$Borrower.run(AbstractPool.java:317) ~[reactor-netty-0.9.0.RELEASE.jar!/:0.9.0.RELEASE]
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been …
Run Code Online (Sandbox Code Playgroud) 长期以来,Spring 一直推荐使用RestTemplate来同步 http 请求。然而,现在的文档说:
注意:从 5.0 开始,此类处于维护模式,仅接受较小的更改请求和错误。请考虑使用 org.springframework.web.reactive.client.WebClient ,它具有更现代的 API 并支持同步、异步和流场景。
但我还没有看到如何建议使用WebClient进行同步场景。文档中有这样的内容:
WebClient 可以通过在结果结束时阻塞来以同步方式使用
我已经看到一些代码库到处都使用 .block() 。然而,我的问题是,凭借一些反应式框架的经验,我逐渐明白阻止反应式调用是一种代码味道,实际上应该只在测试中使用。例如这个页面说
有时,您只能将部分代码迁移为响应式,并且需要在更多命令式代码中重用响应式序列。
因此,如果您需要阻塞直到 Mono 的值可用,请使用 Mono#block() 方法。如果 onError 事件被触发,它将抛出异常。
请注意,您应该通过尽可能支持端到端的反应式代码来避免这种情况。您必须在其他反应式代码中间不惜一切代价避免这种情况,因为这有可能锁定整个反应式管道。
那么我是否错过了一些可以避免 block() 但允许您进行同步调用的东西,或者是否在任何地方都使用 block() 真的是这样?
或者 WebClient API 的意图是暗示人们不应该再在代码库中的任何地方进行阻塞?由于 WebClient 似乎是 Spring 提供的未来 http 调用的唯一替代方案,因此未来在整个代码库中使用非阻塞调用并更改代码库的其余部分以适应这一点是唯一可行的选择吗?
这里有一个相关的问题,但它只关注发生的异常,而我有兴趣听到一般的方法应该是什么。
获取输入常规 java 有效负载的控制器与反应式有效负载的控制器之间有什么区别?例如,假设我有以下 2 个端点:
@RestController
public class MyController {
@PostMapping
public Flux<SomeObject> doThing(@RequestBody MyPayload playlod) {
// do things that return flux - reactive all the way from this controller
Run Code Online (Sandbox Code Playgroud)
和这个:
@RestController
public class MyController {
@PostMapping
public Flux<SomeObject> doThing(@RequestBody Mono<MyPayload> playlod) {
Run Code Online (Sandbox Code Playgroud)
从反应性的角度来看,我不明白这两种方法之间的区别。
reactive ×10
java ×3
spring ×3
spring-boot ×3
.net ×1
angular ×1
c# ×1
forms ×1
nuget ×1
r ×1
reactiveui ×1
shiny ×1
spring-ldap ×1
spring5 ×1
synchronous ×1
validation ×1
webclient ×1