Search in sources :

Example 1 with Aggregator

use of org.springframework.integration.annotation.Aggregator 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 2 with Aggregator

use of org.springframework.integration.annotation.Aggregator 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 3 with Aggregator

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

the class TestAnnotatedEndpointWithCustomizedAggregator method aggregatingMethod.

@Aggregator(inputChannel = "inputChannel", outputChannel = "outputChannel", discardChannel = "discardChannel", sendPartialResultsOnExpiry = "true", sendTimeout = "98765432")
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());
    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 4 with Aggregator

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

the class TestAggregatorBean method createSingleMessageFromGroup.

@Aggregator
public Message<?> createSingleMessageFromGroup(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());
    if (correlationId != null) {
        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)

Aggregations

ArrayList (java.util.ArrayList)4 IntegrationMessageHeaderAccessor (org.springframework.integration.IntegrationMessageHeaderAccessor)4 MessageSequenceComparator (org.springframework.integration.aggregator.MessageSequenceComparator)4 Aggregator (org.springframework.integration.annotation.Aggregator)4 Message (org.springframework.messaging.Message)4 GenericMessage (org.springframework.messaging.support.GenericMessage)4