use of org.springframework.integration.channel.FluxMessageChannel in project spring-integration by spring-projects.
the class IntegrationFlows method from.
/**
* Populate a {@link FluxMessageChannel} to the {@link IntegrationFlowBuilder} chain
* and subscribe it to the provided {@link Publisher}.
* @param publisher the {@link Publisher} to subscribe to.
* @return new {@link IntegrationFlowBuilder}.
*/
public static IntegrationFlowBuilder from(Publisher<Message<?>> publisher) {
FluxMessageChannel reactiveChannel = new FluxMessageChannel();
reactiveChannel.subscribeTo(publisher);
return from((MessageChannel) reactiveChannel);
}
use of org.springframework.integration.channel.FluxMessageChannel in project spring-integration by spring-projects.
the class DefaultSplitterTests method splitArrayPayloadReactive.
@Test
public void splitArrayPayloadReactive() {
Message<?> message = new GenericMessage<>(new String[] { "x", "y", "z" });
FluxMessageChannel replyChannel = new FluxMessageChannel();
DefaultMessageSplitter splitter = new DefaultMessageSplitter();
splitter.setOutputChannel(replyChannel);
splitter.handleMessage(message);
Flux<String> testFlux = Flux.from(replyChannel).map(Message::getPayload).cast(String.class);
StepVerifier.create(testFlux).expectNext("x", "y", "z").then(() -> ((Subscriber<?>) TestUtils.getPropertyValue(replyChannel, "subscribers", List.class).get(0)).onComplete()).verifyComplete();
}
use of org.springframework.integration.channel.FluxMessageChannel in project spring-integration by spring-projects.
the class DefaultSplitterTests method splitStreamReactive.
@Test
public void splitStreamReactive() {
Message<?> message = new GenericMessage<>(Stream.of("x", "y", "z"));
FluxMessageChannel replyChannel = new FluxMessageChannel();
DefaultMessageSplitter splitter = new DefaultMessageSplitter();
splitter.setOutputChannel(replyChannel);
splitter.handleMessage(message);
Flux<String> testFlux = Flux.from(replyChannel).map(Message::getPayload).cast(String.class);
StepVerifier.create(testFlux).expectNext("x", "y", "z").then(() -> ((Subscriber<?>) TestUtils.getPropertyValue(replyChannel, "subscribers", List.class).get(0)).onComplete()).verifyComplete();
}
use of org.springframework.integration.channel.FluxMessageChannel in project spring-integration by spring-projects.
the class DefaultSplitterTests method splitFluxReactive.
@Test
public void splitFluxReactive() {
Message<?> message = new GenericMessage<>(Flux.just("x", "y", "z"));
FluxMessageChannel replyChannel = new FluxMessageChannel();
DefaultMessageSplitter splitter = new DefaultMessageSplitter();
splitter.setOutputChannel(replyChannel);
splitter.handleMessage(message);
Flux<String> testFlux = Flux.from(replyChannel).map(Message::getPayload).cast(String.class);
StepVerifier.create(testFlux).expectNext("x", "y", "z").then(() -> ((Subscriber<?>) TestUtils.getPropertyValue(replyChannel, "subscribers", List.class).get(0)).onComplete()).verifyComplete();
}
use of org.springframework.integration.channel.FluxMessageChannel in project spring-integration by spring-projects.
the class WebFluxRequestExecutingMessageHandlerTests method testReactiveReturn.
@Test
public void testReactiveReturn() {
ClientHttpConnector httpConnector = new HttpHandlerConnector((request, response) -> {
response.setStatusCode(HttpStatus.OK);
return Mono.defer(response::setComplete);
});
WebClient webClient = WebClient.builder().clientConnector(httpConnector).build();
String destinationUri = "http://www.springsource.org/spring-integration";
WebFluxRequestExecutingMessageHandler reactiveHandler = new WebFluxRequestExecutingMessageHandler(destinationUri, webClient);
FluxMessageChannel ackChannel = new FluxMessageChannel();
reactiveHandler.setOutputChannel(ackChannel);
reactiveHandler.handleMessage(MessageBuilder.withPayload("hello, world").build());
reactiveHandler.handleMessage(MessageBuilder.withPayload("hello, world").build());
StepVerifier.create(ackChannel, 2).assertNext(m -> assertThat(m, hasHeader(HttpHeaders.STATUS_CODE, HttpStatus.OK))).assertNext(m -> assertThat(m, hasHeader(HttpHeaders.STATUS_CODE, HttpStatus.OK))).then(() -> ((Subscriber<?>) TestUtils.getPropertyValue(ackChannel, "subscribers", List.class).get(0)).onComplete()).verifyComplete();
}
Aggregations