7 Eylül 2023 Perşembe

SpringIntegration Aggregator

Giriş
Açıklaması şöyle
An Aggregator collects and combines messages that share a common correlation before sending them as a single message.
Örnek
Şöyle yaparız
@Configuration
public class AggregatorConfig {

    @Bean
    public MessageChannel inputChannel() {
        return new DirectChannel();
    }

    @Bean
    public MessageChannel outputChannel() {
        return new DirectChannel();
    }

    @Bean
    @Transformer(inputChannel = "inputChannel", outputChannel = "aggregatorChannel")
    public HeaderEnricher correlationHeaderEnricher() {
        Map<String, Expression> headersToAdd = new HashMap<>();
        headersToAdd.put("correlationId", new ValueExpression<>("aggregatedPayload"));
        return new HeaderEnricher(headersToAdd);
    }

    @Bean
    public PollableChannel aggregatorChannel() {
        return new QueueChannel();
    }

    @Bean
    @Aggregator(inputChannel = "aggregatorChannel", outputChannel = "outputChannel")
    public DefaultAggregatingMessageGroupProcessor aggregator() {
        return new DefaultAggregatingMessageGroupProcessor();
    }
}
Açıklaması şöyle
In this configuration, we define two DirectChannel beans: inputChannel and outputChannel. We use a Transformer to enrich the message headers with a correlationId. The Aggregator combines messages with the same correlationId and sends the aggregated message to the outputChannel.
Örn

Hiç yorum yok:

Yorum Gönder