Search in sources :

Example 41 with IntegrationMessageHeaderAccessor

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

the class RecipientListRouterTests method applySequenceEnabled.

@Test
public void applySequenceEnabled() {
    QueueChannel channelA = new QueueChannel(1);
    QueueChannel channelB = new QueueChannel(1);
    channelA.setBeanName("channelA");
    channelB.setBeanName("channelB");
    RecipientListRouter router = new RecipientListRouter();
    router.setApplySequence(true);
    List<MessageChannel> channels = new ArrayList<MessageChannel>();
    channels.add(channelA);
    channels.add(channelB);
    router.setChannels(channels);
    Message<String> message = new GenericMessage<String>("test");
    router.handleMessage(message);
    Message<?> result1a = channelA.receive(0);
    Message<?> result1b = channelB.receive(0);
    assertNotNull(result1a);
    assertNotNull(result1b);
    assertEquals("test", result1a.getPayload());
    assertEquals(1, new IntegrationMessageHeaderAccessor(result1a).getSequenceNumber());
    assertEquals(2, new IntegrationMessageHeaderAccessor(result1a).getSequenceSize());
    assertEquals(message.getHeaders().getId(), new IntegrationMessageHeaderAccessor(result1a).getCorrelationId());
    assertEquals("test", result1b.getPayload());
    assertEquals(2, new IntegrationMessageHeaderAccessor(result1b).getSequenceNumber());
    assertEquals(2, new IntegrationMessageHeaderAccessor(result1b).getSequenceSize());
    assertEquals(message.getHeaders().getId(), new IntegrationMessageHeaderAccessor(result1b).getCorrelationId());
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) QueueChannel(org.springframework.integration.channel.QueueChannel) MessageChannel(org.springframework.messaging.MessageChannel) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 42 with IntegrationMessageHeaderAccessor

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

the class RecipientListRouterTests method applySequenceNotEnabledByDefault.

@Test
public void applySequenceNotEnabledByDefault() {
    QueueChannel channelA = new QueueChannel(1);
    QueueChannel channelB = new QueueChannel(1);
    channelA.setBeanName("channelA");
    channelB.setBeanName("channelB");
    RecipientListRouter router = new RecipientListRouter();
    List<MessageChannel> channels = new ArrayList<MessageChannel>();
    channels.add(channelA);
    channels.add(channelB);
    router.setChannels(channels);
    Message<String> message = new GenericMessage<String>("test");
    router.handleMessage(message);
    Message<?> result1a = channelA.receive(0);
    Message<?> result1b = channelB.receive(0);
    assertNotNull(result1a);
    assertNotNull(result1b);
    assertEquals("test", result1a.getPayload());
    assertEquals(0, new IntegrationMessageHeaderAccessor(result1a).getSequenceNumber());
    assertEquals(0, new IntegrationMessageHeaderAccessor(result1a).getSequenceSize());
    assertNull(new IntegrationMessageHeaderAccessor(result1a).getCorrelationId());
    assertEquals("test", result1b.getPayload());
    assertEquals(0, new IntegrationMessageHeaderAccessor(result1b).getSequenceNumber());
    assertEquals(0, new IntegrationMessageHeaderAccessor(result1b).getSequenceSize());
    assertNull(new IntegrationMessageHeaderAccessor(result1b).getCorrelationId());
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) QueueChannel(org.springframework.integration.channel.QueueChannel) MessageChannel(org.springframework.messaging.MessageChannel) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 43 with IntegrationMessageHeaderAccessor

use of org.springframework.integration.IntegrationMessageHeaderAccessor 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 44 with IntegrationMessageHeaderAccessor

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

the class ResequencerTests method testResequencingWithDuplicateMessages.

@Test
public void testResequencingWithDuplicateMessages() {
    QueueChannel replyChannel = new QueueChannel();
    Message<?> message1 = createMessage("123", "ABC", 3, 3, replyChannel);
    Message<?> message2 = createMessage("456", "ABC", 3, 1, replyChannel);
    Message<?> message3 = createMessage("789", "ABC", 3, 2, replyChannel);
    this.resequencer.handleMessage(message1);
    this.resequencer.handleMessage(message3);
    this.resequencer.handleMessage(message3);
    this.resequencer.handleMessage(message2);
    Message<?> reply1 = replyChannel.receive(0);
    Message<?> reply2 = replyChannel.receive(0);
    Message<?> reply3 = replyChannel.receive(0);
    assertNotNull(reply1);
    assertEquals(1, new IntegrationMessageHeaderAccessor(reply1).getSequenceNumber());
    assertNotNull(reply2);
    assertEquals(2, new IntegrationMessageHeaderAccessor(reply2).getSequenceNumber());
    assertNotNull(reply3);
    assertEquals(3, new IntegrationMessageHeaderAccessor(reply3).getSequenceNumber());
}
Also used : IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) QueueChannel(org.springframework.integration.channel.QueueChannel) Test(org.junit.Test)

Example 45 with IntegrationMessageHeaderAccessor

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

the class ResequencerTests method testResequencingWithDifferentSequenceSizes.

@Test
public void testResequencingWithDifferentSequenceSizes() throws InterruptedException {
    QueueChannel discardChannel = new QueueChannel();
    Message<?> message1 = createMessage("123", "ABC", 4, 2, null);
    Message<?> message2 = createMessage("456", "ABC", 5, 1, null);
    this.resequencer.setSendPartialResultOnExpiry(false);
    this.resequencer.setDiscardChannel(discardChannel);
    // force SequenceSizeReleaseStrategy
    this.resequencer.setReleasePartialSequences(true);
    this.resequencer.handleMessage(message1);
    this.resequencer.handleMessage(message2);
    // this.resequencer.discardBarrier(this.resequencer.barriers.get("ABC"));
    Message<?> discard1 = discardChannel.receive(0);
    Message<?> discard2 = discardChannel.receive(0);
    // message2 has been discarded because it came in with the wrong sequence size
    assertNotNull(discard1);
    assertEquals(1, new IntegrationMessageHeaderAccessor(discard1).getSequenceNumber());
    assertNull(discard2);
}
Also used : IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) QueueChannel(org.springframework.integration.channel.QueueChannel) 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