use of org.springframework.integration.channel.FluxMessageChannel in project spring-integration by spring-projects.
the class FileSplitterTests method testFileSplitterReactive.
@Test
public void testFileSplitterReactive() {
FluxMessageChannel outputChannel = new FluxMessageChannel();
FileSplitter splitter = new FileSplitter(true, true);
splitter.setApplySequence(true);
splitter.setOutputChannel(outputChannel);
splitter.handleMessage(new GenericMessage<>(file));
StepVerifier.create(outputChannel).assertNext(m -> {
assertThat(m, hasHeaderKey(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE));
assertThat(m, hasHeader(FileHeaders.MARKER, "START"));
assertThat(m, hasPayload(instanceOf(FileSplitter.FileMarker.class)));
FileMarker fileMarker = (FileSplitter.FileMarker) m.getPayload();
assertEquals(FileMarker.Mark.START, fileMarker.getMark());
assertEquals(file.getAbsolutePath(), fileMarker.getFilePath());
}).expectNextCount(2).assertNext(m -> {
assertThat(m, hasHeader(FileHeaders.MARKER, "END"));
assertThat(m, hasPayload(instanceOf(FileSplitter.FileMarker.class)));
FileMarker fileMarker = (FileSplitter.FileMarker) m.getPayload();
assertEquals(FileMarker.Mark.END, fileMarker.getMark());
assertEquals(file.getAbsolutePath(), fileMarker.getFilePath());
assertEquals(2, fileMarker.getLineCount());
}).then(() -> ((Subscriber<?>) TestUtils.getPropertyValue(outputChannel, "subscribers", List.class).get(0)).onComplete()).verifyComplete();
}
use of org.springframework.integration.channel.FluxMessageChannel in project spring-integration by spring-projects.
the class ReactiveStreamsConsumerTests method testReactiveStreamsConsumerViaConsumerEndpointFactoryBean.
@Test
public void testReactiveStreamsConsumerViaConsumerEndpointFactoryBean() throws Exception {
FluxMessageChannel testChannel = new FluxMessageChannel();
List<Message<?>> result = new LinkedList<>();
CountDownLatch stopLatch = new CountDownLatch(3);
MessageHandler messageHandler = m -> {
result.add(m);
stopLatch.countDown();
};
ConsumerEndpointFactoryBean endpointFactoryBean = new ConsumerEndpointFactoryBean();
endpointFactoryBean.setBeanFactory(mock(ConfigurableBeanFactory.class));
endpointFactoryBean.setInputChannel(testChannel);
endpointFactoryBean.setHandler(messageHandler);
endpointFactoryBean.setBeanName("reactiveConsumer");
endpointFactoryBean.afterPropertiesSet();
endpointFactoryBean.start();
Message<?> testMessage = new GenericMessage<>("test");
testChannel.send(testMessage);
endpointFactoryBean.stop();
try {
testChannel.send(testMessage);
} catch (Exception e) {
assertThat(e, instanceOf(MessageDeliveryException.class));
assertThat(e.getCause(), instanceOf(IllegalStateException.class));
assertThat(e.getMessage(), containsString("doesn't have subscribers to accept messages"));
}
endpointFactoryBean.start();
Message<?> testMessage2 = new GenericMessage<>("test2");
testChannel.send(testMessage2);
testChannel.send(testMessage2);
assertTrue(stopLatch.await(10, TimeUnit.SECONDS));
assertThat(result.size(), equalTo(3));
assertThat(result, Matchers.<Message<?>>contains(testMessage, testMessage2, testMessage2));
}
use of org.springframework.integration.channel.FluxMessageChannel in project spring-integration by spring-projects.
the class ReactiveStreamsConsumerTests method testReactiveStreamsConsumerFluxMessageChannel.
@Test
public void testReactiveStreamsConsumerFluxMessageChannel() throws InterruptedException {
FluxMessageChannel testChannel = new FluxMessageChannel();
List<Message<?>> result = new LinkedList<>();
CountDownLatch stopLatch = new CountDownLatch(2);
MessageHandler messageHandler = m -> {
result.add(m);
stopLatch.countDown();
};
MessageHandler testSubscriber = new MethodInvokingMessageHandler(messageHandler, (String) null);
ReactiveStreamsConsumer reactiveConsumer = new ReactiveStreamsConsumer(testChannel, testSubscriber);
reactiveConsumer.setBeanFactory(mock(BeanFactory.class));
reactiveConsumer.afterPropertiesSet();
reactiveConsumer.start();
Message<?> testMessage = new GenericMessage<>("test");
testChannel.send(testMessage);
reactiveConsumer.stop();
try {
testChannel.send(testMessage);
} catch (Exception e) {
assertThat(e, instanceOf(MessageDeliveryException.class));
assertThat(e.getCause(), instanceOf(IllegalStateException.class));
assertThat(e.getMessage(), containsString("doesn't have subscribers to accept messages"));
}
reactiveConsumer.start();
Message<?> testMessage2 = new GenericMessage<>("test2");
testChannel.send(testMessage2);
assertTrue(stopLatch.await(10, TimeUnit.SECONDS));
assertThat(result, Matchers.<Message<?>>contains(testMessage, testMessage2));
}
use of org.springframework.integration.channel.FluxMessageChannel in project spring-integration by spring-projects.
the class IntegrationFlowDefinition method toReactivePublisher.
/**
* Represent an Integration Flow as a Reactive Streams {@link Publisher} bean.
* @param <T> the expected {@code payload} type
* @return the Reactive Streams {@link Publisher}
*/
@SuppressWarnings("unchecked")
public <T> Publisher<Message<T>> toReactivePublisher() {
MessageChannel channelForPublisher = this.currentMessageChannel;
Publisher<Message<T>> publisher;
if (channelForPublisher instanceof Publisher) {
publisher = (Publisher<Message<T>>) channelForPublisher;
} else {
if (channelForPublisher != null) {
publisher = MessageChannelReactiveUtils.toPublisher(channelForPublisher);
} else {
MessageChannel reactiveChannel = new FluxMessageChannel();
publisher = (Publisher<Message<T>>) reactiveChannel;
channel(reactiveChannel);
}
}
get();
return new PublisherIntegrationFlow<>(this.integrationComponents, publisher);
}
Aggregations