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());
}
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());
}
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;
}
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;
}
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());
}
Aggregations