Search in sources :

Example 11 with SimpleMessageStore

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

the class ClaimCheckTransformerTests method store.

@Test
public void store() {
    MessageStore store = new SimpleMessageStore(10);
    ClaimCheckInTransformer transformer = new ClaimCheckInTransformer(store);
    Message<?> input = MessageBuilder.withPayload("test").build();
    Message<?> output = transformer.transform(input);
    assertEquals(input.getHeaders().getId(), output.getPayload());
}
Also used : MessageStore(org.springframework.integration.store.MessageStore) SimpleMessageStore(org.springframework.integration.store.SimpleMessageStore) SimpleMessageStore(org.springframework.integration.store.SimpleMessageStore) Test(org.junit.Test)

Example 12 with SimpleMessageStore

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

the class ClaimCheckTransformerTests method retrieve.

@Test
public void retrieve() {
    MessageStore store = new SimpleMessageStore(10);
    Message<?> message = MessageBuilder.withPayload("test").build();
    UUID storedId = message.getHeaders().getId();
    store.addMessage(message);
    ClaimCheckOutTransformer transformer = new ClaimCheckOutTransformer(store);
    Message<?> input = MessageBuilder.withPayload(storedId).build();
    Message<?> output = transformer.transform(input);
    assertEquals("test", output.getPayload());
}
Also used : MessageStore(org.springframework.integration.store.MessageStore) SimpleMessageStore(org.springframework.integration.store.SimpleMessageStore) SimpleMessageStore(org.springframework.integration.store.SimpleMessageStore) UUID(java.util.UUID) Test(org.junit.Test)

Example 13 with SimpleMessageStore

use of org.springframework.integration.store.SimpleMessageStore 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)

Example 14 with SimpleMessageStore

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

the class ResequencerTests method testResequencingWithIncompleteSequenceRelease.

@Test
public void testResequencingWithIncompleteSequenceRelease() throws InterruptedException {
    this.resequencer.setReleaseStrategy(new SequenceSizeReleaseStrategy(true));
    // INT-3846
    this.resequencer.setMessageStore(new SimpleMessageStore(3));
    QueueChannel replyChannel = new QueueChannel();
    Message<?> message1 = createMessage("123", "ABC", 4, 4, replyChannel);
    Message<?> message2 = createMessage("456", "ABC", 4, 2, replyChannel);
    // release 2 after this one
    Message<?> message3 = createMessage("789", "ABC", 4, 1, replyChannel);
    Message<?> message4 = createMessage("XYZ", "ABC", 4, 3, replyChannel);
    this.resequencer.handleMessage(message1);
    this.resequencer.handleMessage(message2);
    this.resequencer.handleMessage(message3);
    Message<?> reply1 = replyChannel.receive(0);
    Message<?> reply2 = replyChannel.receive(0);
    Message<?> reply3 = replyChannel.receive(0);
    // only messages 1 and 2 should have been received by now
    assertNotNull(reply1);
    assertEquals(1, new IntegrationMessageHeaderAccessor(reply1).getSequenceNumber());
    assertNotNull(reply2);
    assertEquals(2, new IntegrationMessageHeaderAccessor(reply2).getSequenceNumber());
    assertNull(reply3);
    // when sending the last message, the whole sequence must have been sent
    this.resequencer.handleMessage(message4);
    reply3 = replyChannel.receive(0);
    Message<?> reply4 = replyChannel.receive(0);
    assertNotNull(reply3);
    assertEquals(3, new IntegrationMessageHeaderAccessor(reply3).getSequenceNumber());
    assertNotNull(reply4);
    assertEquals(4, new IntegrationMessageHeaderAccessor(reply4).getSequenceNumber());
}
Also used : IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) SimpleMessageStore(org.springframework.integration.store.SimpleMessageStore) QueueChannel(org.springframework.integration.channel.QueueChannel) Test(org.junit.Test)

Example 15 with SimpleMessageStore

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

the class DelayHandler method doInit.

@Override
protected void doInit() {
    if (this.messageStore == null) {
        this.messageStore = new SimpleMessageStore();
    } else {
        Assert.isInstanceOf(MessageStore.class, this.messageStore);
    }
    this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(this.getBeanFactory());
    this.releaseHandler = this.createReleaseMessageTask();
}
Also used : SimpleMessageStore(org.springframework.integration.store.SimpleMessageStore)

Aggregations

SimpleMessageStore (org.springframework.integration.store.SimpleMessageStore)25 Test (org.junit.Test)20 GenericMessage (org.springframework.messaging.support.GenericMessage)10 MessageGroupStore (org.springframework.integration.store.MessageGroupStore)8 Message (org.springframework.messaging.Message)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 MessageGroupQueue (org.springframework.integration.store.MessageGroupQueue)6 LongRunningIntegrationTest (org.springframework.integration.test.support.LongRunningIntegrationTest)6 QueueChannel (org.springframework.integration.channel.QueueChannel)5 ArrayList (java.util.ArrayList)4 Collection (java.util.Collection)3 MessageStore (org.springframework.integration.store.MessageStore)3 UUID (java.util.UUID)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ExecutorService (java.util.concurrent.ExecutorService)2 DirectChannel (org.springframework.integration.channel.DirectChannel)2 MessageGroup (org.springframework.integration.store.MessageGroup)2 SimpleMessageGroupFactory (org.springframework.integration.store.SimpleMessageGroupFactory)2 StopWatch (org.springframework.util.StopWatch)2 Method (java.lang.reflect.Method)1