Search in sources :

Example 16 with IntegrationMessageHeaderAccessor

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

the class ResequencerTests method testResequencingWithDiscard.

@Test
public void testResequencingWithDiscard() throws InterruptedException {
    QueueChannel discardChannel = new QueueChannel();
    Message<?> message1 = createMessage("123", "ABC", 4, 2, null);
    Message<?> message2 = createMessage("456", "ABC", 4, 1, null);
    Message<?> message3 = createMessage("789", "ABC", 4, 4, null);
    this.resequencer.setSendPartialResultOnExpiry(false);
    this.resequencer.setDiscardChannel(discardChannel);
    this.resequencer.handleMessage(message1);
    this.resequencer.handleMessage(message2);
    assertEquals(1, store.expireMessageGroups(-10000));
    Message<?> reply1 = discardChannel.receive(0);
    Message<?> reply2 = discardChannel.receive(0);
    Message<?> reply3 = discardChannel.receive(0);
    // only messages 1 and 2 should have been received by now
    assertNotNull(reply1);
    assertNotNull(reply2);
    assertNull(reply3);
    ArrayList<Integer> sequence = new ArrayList<>(Arrays.asList(new IntegrationMessageHeaderAccessor(reply1).getSequenceNumber(), new IntegrationMessageHeaderAccessor(reply2).getSequenceNumber()));
    Collections.sort(sequence);
    assertEquals("[1, 2]", sequence.toString());
    // Once a group is expired, late messages are discarded immediately by default
    this.resequencer.handleMessage(message3);
    reply3 = discardChannel.receive(0);
    assertNotNull(reply3);
}
Also used : IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) QueueChannel(org.springframework.integration.channel.QueueChannel) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 17 with IntegrationMessageHeaderAccessor

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

the class MethodInvokingReleaseStrategyTests method testAdapterWithNonParameterizedMessageListBasedMethod.

@Test
public void testAdapterWithNonParameterizedMessageListBasedMethod() {
    class TestReleaseStrategy {

        @SuppressWarnings("unused")
        public boolean checkCompletenessOnNonParameterizedListOfMessages(List<Message<?>> messages) {
            Assert.assertTrue(messages.size() > 0);
            return messages.size() > new IntegrationMessageHeaderAccessor(messages.iterator().next()).getSequenceSize();
        }
    }
    ReleaseStrategy adapter = new MethodInvokingReleaseStrategy(new TestReleaseStrategy(), "checkCompletenessOnNonParameterizedListOfMessages");
    MessageGroup messages = createListOfMessages(3);
    Assert.assertTrue(adapter.canRelease(messages));
}
Also used : IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 18 with IntegrationMessageHeaderAccessor

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

the class DefaultSplitterTests method splitStream.

@Test
public void splitStream() {
    Message<?> message = new GenericMessage<>(Stream.generate(Math::random).limit(10));
    QueueChannel outputChannel = new QueueChannel();
    DefaultMessageSplitter splitter = new DefaultMessageSplitter();
    splitter.setOutputChannel(outputChannel);
    splitter.handleMessage(message);
    for (int i = 0; i < 10; i++) {
        Message<?> reply = outputChannel.receive(0);
        assertEquals(message.getHeaders().getId(), new IntegrationMessageHeaderAccessor(reply).getCorrelationId());
    }
    assertNull(outputChannel.receive(10));
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) QueueChannel(org.springframework.integration.channel.QueueChannel) Test(org.junit.Test)

Example 19 with IntegrationMessageHeaderAccessor

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

the class DefaultSplitterTests method correlationIdCopiedFromMessageId.

@Test
public void correlationIdCopiedFromMessageId() {
    Message<String> message = MessageBuilder.withPayload("test").build();
    DirectChannel inputChannel = new DirectChannel();
    QueueChannel outputChannel = new QueueChannel(1);
    DefaultMessageSplitter splitter = new DefaultMessageSplitter();
    splitter.setOutputChannel(outputChannel);
    EventDrivenConsumer endpoint = new EventDrivenConsumer(inputChannel, splitter);
    endpoint.start();
    assertTrue(inputChannel.send(message));
    Message<?> reply = outputChannel.receive(0);
    assertEquals(message.getHeaders().getId(), new IntegrationMessageHeaderAccessor(reply).getCorrelationId());
}
Also used : IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) QueueChannel(org.springframework.integration.channel.QueueChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) Test(org.junit.Test)

Example 20 with IntegrationMessageHeaderAccessor

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

the class MethodInvokingSplitterTests method headerForObjectReturnValues.

@Test
public void headerForObjectReturnValues() throws Exception {
    GenericMessage<String> message = new GenericMessage<String>("foo.bar");
    MethodInvokingSplitter splitter = this.getSplitter("stringToStringArray");
    QueueChannel replyChannel = new QueueChannel();
    splitter.setOutputChannel(replyChannel);
    splitter.handleMessage(message);
    List<Message<?>> replies = replyChannel.clear();
    Message<?> reply1 = replies.get(0);
    assertNotNull(reply1);
    assertEquals(2, new IntegrationMessageHeaderAccessor(reply1).getSequenceSize());
    assertEquals(1, new IntegrationMessageHeaderAccessor(reply1).getSequenceNumber());
    assertEquals(message.getHeaders().getId(), new IntegrationMessageHeaderAccessor(reply1).getCorrelationId());
    Message<?> reply2 = replies.get(1);
    assertNotNull(reply2);
    assertEquals(2, new IntegrationMessageHeaderAccessor(reply2).getSequenceSize());
    assertEquals(2, new IntegrationMessageHeaderAccessor(reply2).getSequenceNumber());
    assertEquals(message.getHeaders().getId(), new IntegrationMessageHeaderAccessor(reply2).getCorrelationId());
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) QueueChannel(org.springframework.integration.channel.QueueChannel) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) Test(org.junit.Test)

Aggregations

IntegrationMessageHeaderAccessor (org.springframework.integration.IntegrationMessageHeaderAccessor)68 Test (org.junit.Test)56 QueueChannel (org.springframework.integration.channel.QueueChannel)32 Message (org.springframework.messaging.Message)21 GenericMessage (org.springframework.messaging.support.GenericMessage)19 MessageChannel (org.springframework.messaging.MessageChannel)15 ArrayList (java.util.ArrayList)10 MessagingTemplate (org.springframework.integration.core.MessagingTemplate)9 DirectChannel (org.springframework.integration.channel.DirectChannel)8 ServiceActivatingHandler (org.springframework.integration.handler.ServiceActivatingHandler)6 List (java.util.List)5 BeanFactory (org.springframework.beans.factory.BeanFactory)5 MessageSequenceComparator (org.springframework.integration.aggregator.MessageSequenceComparator)4 Aggregator (org.springframework.integration.annotation.Aggregator)4 InputStream (java.io.InputStream)3 LinkedList (java.util.LinkedList)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)3 MessageGroup (org.springframework.integration.store.MessageGroup)3 SimpleMessageGroup (org.springframework.integration.store.SimpleMessageGroup)3