使用JavaDSL时,为什么我必须在入站webflux网关上使用.fluxTransform(f->;f)?
在Spring集成中使用webflux网关Java DSL时,我遇到了失败的回复。它只对第一个流中的前几个请求(f)起作用,是否使它起作用使用JavaDSL时,为什么我必须在入站webflux网关上使用.fluxTransform(f->;f)?,java,spring,spring-integration,spring-integration-dsl,spring-integration-http,Java,Spring,Spring Integration,Spring Integration Dsl,Spring Integration Http,在Spring集成中使用webflux网关Java DSL时,我遇到了失败的回复。它只对第一个流中的前几个请求(f)起作用,是否使它起作用 当我在第二个流中使用Http.outboundGateway时,为什么没有fluxTransform(f->f) 场景 我使用四个网关创建了一个路由,用于在远程机器上进行web请求的相当复杂的设置,但我 集成流程1: 入站webflux网关->出站jms网关 @Bean 公共集成流步骤1(){ //使用jms出站网关的请求-应答模式 var gateway
Http.outboundGateway
时,为什么没有fluxTransform(f->f)
我使用四个网关创建了一个路由,用于在远程机器上进行web请求的相当复杂的设置,但我 集成流程1: 入站webflux网关->出站jms网关
@Bean
公共集成流步骤1(){
//使用jms出站网关的请求-应答模式
var gateway=Jms.outboundGateway(jmsConnectionFactory)
.requestDestination(“inboundWebfluxQueue”)
.replyDestination(“outboundWebfluxQueue”)
.correlationKey(“JMSCorrelationID”);
//向jms发送请求,等待回复并将消息负载作为响应返回
返回IntegrationFlows.from(webfluxServer(“/example/webflux”))
//如果没有下一行,将无法持续工作
.fluxTransform(f->f)
.handle(网关).get();
}
集成流程2:
入站jms网关->出站webflux网关
@Bean
使用webflux()的公共集成流步骤2{
var gateway=WebFlux.outboundGateway(“http://localhost:8080/actuator/health")
.httpMethod(httpMethod.GET)
.expectedResponseType(String.class)
//忽略标题
.mappedResponseHeaders();
返回IntegrationFlows.from(jmsInboundGateway())
//使用webflux出站网关将请求发送到测试URL
.handle(网关).get();
}
整个路线如下所示:
客户端web请求->流1->(MessageBroker)->流2->服务器web请求
另一种方法是使用
.channel(MessageChannels.flux())
而不是.fluxTransform(f->f)
。通过这种方式,我们确实给WebFlux容器带来了一个背压,使其在请求事件循环中等待可用的插槽
有了它,我们只发送到JMS队列,而不接受背压,而另一端的JMS消费者无法跟上。另外,我们向同一个Netty服务器发送一个请求,在内部为这些内部请求再次获取一个事件循环槽
如果您感兴趣,我写了一个类似这样的单元测试来看看发生了什么:
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class IntegrationApplicationTests {
@Autowired
private TestRestTemplate template;
@Test
void testSpringIntegrationWebFlux() {
var executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(100);
executor.setWaitForTasksToCompleteOnShutdown(true);
executor.setAwaitTerminationSeconds(10);
executor.afterPropertiesSet();
var numberOfExecutions = new AtomicInteger();
for (var i = 0; i < 100; i++) {
executor.execute(() -> {
var responseEntity = this.template.getForEntity("/example/webflux", String.class);
if (responseEntity.getStatusCode().is2xxSuccessful()) {
numberOfExecutions.getAndIncrement();
}
});
}
executor.shutdown();
assertThat(numberOfExecutions.get()).isEqualTo(100);
}
}
@SpringBootTest(webEnvironment=SpringBootTest.webEnvironment.DEFINED\u PORT)
公共类集成应用程序测试{
@自动连线
私有testrest模板;
@试验
void testSpringIntegrationWebFlux(){
var executor=new ThreadPoolTaskExecutor();
执行者。setCorePoolSize(100);
执行器。SetWaitForTaskStoCompletionShutdown(真);
执行器。设置等待终止秒(10);
执行人。AfterPropertieSet();
var numberOfExecutions=新的原子整数();
对于(变量i=0;i<100;i++){
执行者。执行(()->{
var responseEntity=this.template.getForEntity(“/example/webflux”,String.class);
if(responseEntity.getStatusCode().is2xxSuccessful()){
numberOfExecutions.getAndIncrement();
}
});
}
executor.shutdown();
assertThat(numberOfExecutions.get()).isEqualTo(100);
}
}
有没有机会与我们分享一个简单的Spring Boot项目来重现一个问题并播放?当然!我在这里创建了一个最小回购:非常感谢您的见解。