Example usage for org.springframework.integration.aggregator AggregatingMessageHandler setReleasePartialSequences

List of usage examples for org.springframework.integration.aggregator AggregatingMessageHandler setReleasePartialSequences

Introduction

In this page you can find the example usage for org.springframework.integration.aggregator AggregatingMessageHandler setReleasePartialSequences.

Prototype

public void setReleasePartialSequences(boolean releasePartialSequences) 

Source Link

Document

Set releasePartialSequences on an underlying default SequenceSizeReleaseStrategy .

Usage

From source file:org.springframework.integration.aggregator.AggregatorTests.java

@Test
public void testAggPerfDefaultPartial() throws InterruptedException, ExecutionException, TimeoutException {
    AggregatingMessageHandler handler = new AggregatingMessageHandler(
            new DefaultAggregatingMessageGroupProcessor());
    handler.setCorrelationStrategy(message -> "foo");
    handler.setReleasePartialSequences(true);
    DirectChannel outputChannel = new DirectChannel();
    handler.setOutputChannel(outputChannel);

    final CompletableFuture<Collection<?>> resultFuture = new CompletableFuture<>();
    outputChannel.subscribe(message -> {
        Collection<?> payload = (Collection<?>) message.getPayload();
        logger.warn("Received " + payload.size());
        resultFuture.complete(payload);//from  w w w  .j  a v a2 s .  com
    });

    SimpleMessageStore store = new SimpleMessageStore();

    SimpleMessageGroupFactory messageGroupFactory = new SimpleMessageGroupFactory(
            SimpleMessageGroupFactory.GroupType.BLOCKING_QUEUE);

    store.setMessageGroupFactory(messageGroupFactory);

    handler.setMessageStore(store);

    StopWatch stopwatch = new StopWatch();
    stopwatch.start();
    for (int i = 0; i < 120000; i++) {
        if (i % 10000 == 0) {
            stopwatch.stop();
            logger.warn("Sent " + i + " in " + stopwatch.getTotalTimeSeconds() + " (10k in "
                    + stopwatch.getLastTaskTimeMillis() + "ms)");
            stopwatch.start();
        }
        handler.handleMessage(
                MessageBuilder.withPayload("foo").setSequenceSize(120000).setSequenceNumber(i + 1).build());
    }
    stopwatch.stop();
    logger.warn("Sent " + 120000 + " in " + stopwatch.getTotalTimeSeconds() + " (10k in "
            + stopwatch.getLastTaskTimeMillis() + "ms)");

    Collection<?> result = resultFuture.get(10, TimeUnit.SECONDS);
    assertNotNull(result);
    assertEquals(120000, result.size());
    assertThat(stopwatch.getTotalTimeSeconds(), lessThan(60.0)); // actually < 2.0, was many minutes
}