Search in sources :

Example 1 with SimpleMessageGroupFactory

use of org.springframework.integration.store.SimpleMessageGroupFactory in project spring-integration by spring-projects.

the class AggregatorTests method testAggPerfDefaultPartial.

@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);
    });
    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());
    // actually < 2.0, was many minutes
    assertThat(stopwatch.getTotalTimeSeconds(), lessThan(60.0));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) SimpleMessageStore(org.springframework.integration.store.SimpleMessageStore) SimpleMessageGroupFactory(org.springframework.integration.store.SimpleMessageGroupFactory) DirectChannel(org.springframework.integration.channel.DirectChannel) Collection(java.util.Collection) StopWatch(org.springframework.util.StopWatch) Test(org.junit.Test)

Example 2 with SimpleMessageGroupFactory

use of org.springframework.integration.store.SimpleMessageGroupFactory in project spring-integration by spring-projects.

the class AggregatorTests method testAggPerf.

@Test
public void testAggPerf() throws InterruptedException, ExecutionException, TimeoutException {
    AggregatingMessageHandler handler = new AggregatingMessageHandler(new DefaultAggregatingMessageGroupProcessor());
    handler.setCorrelationStrategy(message -> "foo");
    handler.setReleaseStrategy(new MessageCountReleaseStrategy(60000));
    handler.setExpireGroupsUponCompletion(true);
    handler.setSendPartialResultOnExpiry(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);
    });
    SimpleMessageStore store = new SimpleMessageStore();
    SimpleMessageGroupFactory messageGroupFactory = new SimpleMessageGroupFactory(SimpleMessageGroupFactory.GroupType.LIST);
    store.setMessageGroupFactory(messageGroupFactory);
    handler.setMessageStore(store);
    Message<?> message = new GenericMessage<String>("foo");
    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(message);
    }
    stopwatch.stop();
    logger.warn("Sent " + 120000 + " in " + stopwatch.getTotalTimeSeconds() + " (10k in " + stopwatch.getLastTaskTimeMillis() + "ms)");
    Collection<?> result = resultFuture.get(10, TimeUnit.SECONDS);
    assertNotNull(result);
    assertEquals(60000, result.size());
}
Also used : SimpleMessageStore(org.springframework.integration.store.SimpleMessageStore) SimpleMessageGroupFactory(org.springframework.integration.store.SimpleMessageGroupFactory) DirectChannel(org.springframework.integration.channel.DirectChannel) StopWatch(org.springframework.util.StopWatch) GenericMessage(org.springframework.messaging.support.GenericMessage) CompletableFuture(java.util.concurrent.CompletableFuture) Collection(java.util.Collection) Test(org.junit.Test)

Aggregations

Collection (java.util.Collection)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 Test (org.junit.Test)2 DirectChannel (org.springframework.integration.channel.DirectChannel)2 SimpleMessageGroupFactory (org.springframework.integration.store.SimpleMessageGroupFactory)2 SimpleMessageStore (org.springframework.integration.store.SimpleMessageStore)2 StopWatch (org.springframework.util.StopWatch)2 GenericMessage (org.springframework.messaging.support.GenericMessage)1