Search in sources :

Example 11 with IntegrationMessageHeaderAccessor

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

the class HeaderEnricherTests method expirationDateValue.

@Test
public void expirationDateValue() {
    MessagingTemplate template = new MessagingTemplate();
    MessageChannel channel = context.getBean("expirationDateValueInput", MessageChannel.class);
    Message<?> result = template.sendAndReceive(channel, new GenericMessage<String>("test"));
    assertNotNull(result);
    assertEquals(new Long(1111), new IntegrationMessageHeaderAccessor(result).getExpirationDate());
}
Also used : MessagingTemplate(org.springframework.integration.core.MessagingTemplate) IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) MessageChannel(org.springframework.messaging.MessageChannel) Test(org.junit.Test)

Example 12 with IntegrationMessageHeaderAccessor

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

the class HeaderEnricherTests method priority.

@Test
public void priority() {
    MessagingTemplate template = new MessagingTemplate();
    MessageChannel channel = context.getBean("priorityInput", MessageChannel.class);
    Message<?> result = template.sendAndReceive(channel, new GenericMessage<String>("test"));
    assertNotNull(result);
    assertEquals(new Integer(42), new IntegrationMessageHeaderAccessor(result).getPriority());
}
Also used : MessagingTemplate(org.springframework.integration.core.MessagingTemplate) IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) MessageChannel(org.springframework.messaging.MessageChannel) Test(org.junit.Test)

Example 13 with IntegrationMessageHeaderAccessor

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

the class TestAnnotatedEndpointWithDefaultAggregator method aggregatingMethod.

@Aggregator(inputChannel = "inputChannel")
public Message<?> aggregatingMethod(List<Message<?>> messages) {
    List<Message<?>> sortableList = new ArrayList<>(messages);
    Collections.sort(sortableList, new MessageSequenceComparator());
    StringBuffer buffer = new StringBuffer();
    Object correlationId = null;
    for (Message<?> message : sortableList) {
        buffer.append(message.getPayload().toString());
        if (null == correlationId) {
            correlationId = new IntegrationMessageHeaderAccessor(message).getCorrelationId();
        }
    }
    Message<?> returnedMessage = new GenericMessage<>(buffer.toString());
    this.aggregatedMessages.put(correlationId, returnedMessage);
    return returnedMessage;
}
Also used : IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) GenericMessage(org.springframework.messaging.support.GenericMessage) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) MessageSequenceComparator(org.springframework.integration.aggregator.MessageSequenceComparator) ArrayList(java.util.ArrayList) Aggregator(org.springframework.integration.annotation.Aggregator)

Example 14 with IntegrationMessageHeaderAccessor

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

the class TestAnnotatedEndpointWithReleaseStrategy method aggregatingMethod.

@Aggregator(inputChannel = "inputChannel")
public Message<?> aggregatingMethod(List<Message<?>> messages) {
    List<Message<?>> sortableList = new ArrayList<>(messages);
    Collections.sort(sortableList, new MessageSequenceComparator());
    StringBuffer buffer = new StringBuffer();
    Object correlationId = null;
    for (Message<?> message : sortableList) {
        buffer.append(message.getPayload().toString());
        if (null == correlationId) {
            correlationId = new IntegrationMessageHeaderAccessor(message).getCorrelationId();
        }
    }
    Message<?> returnedMessage = new GenericMessage<>(buffer.toString());
    this.aggregatedMessages.put(correlationId, returnedMessage);
    return returnedMessage;
}
Also used : IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) GenericMessage(org.springframework.messaging.support.GenericMessage) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) MessageSequenceComparator(org.springframework.integration.aggregator.MessageSequenceComparator) ArrayList(java.util.ArrayList) Aggregator(org.springframework.integration.annotation.Aggregator)

Example 15 with IntegrationMessageHeaderAccessor

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

the class ResequencerTests method testResequencingWithPartialSequenceAndComparator.

@Test
public void testResequencingWithPartialSequenceAndComparator() throws InterruptedException {
    this.resequencer.setReleaseStrategy(new SequenceSizeReleaseStrategy(true));
    QueueChannel replyChannel = new QueueChannel();
    Message<?> message1 = createMessage("456", "ABC", 4, 2, replyChannel);
    Message<?> message2 = createMessage("123", "ABC", 4, 1, replyChannel);
    Message<?> message3 = createMessage("XYZ", "ABC", 4, 4, replyChannel);
    Message<?> message4 = createMessage("789", "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) 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