Search in sources :

Example 1 with FluxMessageChannel

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);
}
Also used : FluxMessageChannel(org.springframework.integration.channel.FluxMessageChannel)

Example 2 with FluxMessageChannel

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();
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) Subscriber(org.reactivestreams.Subscriber) FluxMessageChannel(org.springframework.integration.channel.FluxMessageChannel) Test(org.junit.Test)

Example 3 with FluxMessageChannel

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();
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) Subscriber(org.reactivestreams.Subscriber) FluxMessageChannel(org.springframework.integration.channel.FluxMessageChannel) Test(org.junit.Test)

Example 4 with FluxMessageChannel

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();
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) Subscriber(org.reactivestreams.Subscriber) FluxMessageChannel(org.springframework.integration.channel.FluxMessageChannel) Test(org.junit.Test)

Example 5 with FluxMessageChannel

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();
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) StepVerifier(reactor.test.StepVerifier) WebClient(org.springframework.web.reactive.function.client.WebClient) FluxMessageChannel(org.springframework.integration.channel.FluxMessageChannel) ErrorMessage(org.springframework.messaging.support.ErrorMessage) TestUtils(org.springframework.integration.test.util.TestUtils) ClientHttpResponse(org.springframework.http.client.reactive.ClientHttpResponse) Assert.assertThat(org.junit.Assert.assertThat) MessageBuilder(org.springframework.integration.support.MessageBuilder) ClientHttpResponseBodyExtractor(org.springframework.integration.webflux.support.ClientHttpResponseBodyExtractor) MessageHandlingException(org.springframework.messaging.MessageHandlingException) HttpHandlerConnector(org.springframework.test.web.reactive.server.HttpHandlerConnector) Message(org.springframework.messaging.Message) Subscriber(org.reactivestreams.Subscriber) Assert.assertNotNull(org.junit.Assert.assertNotNull) MediaType(org.springframework.http.MediaType) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) DataBuffer(org.springframework.core.io.buffer.DataBuffer) HttpHeaders(org.springframework.integration.http.HttpHeaders) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) HttpStatus(org.springframework.http.HttpStatus) Flux(reactor.core.publisher.Flux) HeaderMatcher.hasHeader(org.springframework.integration.test.matcher.HeaderMatcher.hasHeader) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) DataBufferFactory(org.springframework.core.io.buffer.DataBufferFactory) WebClientResponseException(org.springframework.web.reactive.function.client.WebClientResponseException) Matchers.containsString(org.hamcrest.Matchers.containsString) Assert.assertEquals(org.junit.Assert.assertEquals) ClientHttpConnector(org.springframework.http.client.reactive.ClientHttpConnector) ClientHttpConnector(org.springframework.http.client.reactive.ClientHttpConnector) Subscriber(org.reactivestreams.Subscriber) Matchers.containsString(org.hamcrest.Matchers.containsString) FluxMessageChannel(org.springframework.integration.channel.FluxMessageChannel) WebClient(org.springframework.web.reactive.function.client.WebClient) HttpHandlerConnector(org.springframework.test.web.reactive.server.HttpHandlerConnector) Test(org.junit.Test)

Aggregations

FluxMessageChannel (org.springframework.integration.channel.FluxMessageChannel)9 Test (org.junit.Test)7 Subscriber (org.reactivestreams.Subscriber)7 GenericMessage (org.springframework.messaging.support.GenericMessage)5 Message (org.springframework.messaging.Message)4 List (java.util.List)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 Matchers.instanceOf (org.hamcrest.Matchers.instanceOf)3 Assert.assertThat (org.junit.Assert.assertThat)3 QueueChannel (org.springframework.integration.channel.QueueChannel)3 LinkedList (java.util.LinkedList)2 BlockingQueue (java.util.concurrent.BlockingQueue)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2 TimeUnit (java.util.concurrent.TimeUnit)2 Matchers (org.hamcrest.Matchers)2 Matchers.equalTo (org.hamcrest.Matchers.equalTo)2 Assert.assertSame (org.junit.Assert.assertSame)2 Assert.assertTrue (org.junit.Assert.assertTrue)2 Assert.fail (org.junit.Assert.fail)2