Hello,
I'm currently trying to use the aggregator component.
According the doc, there are 2 ways available, i can:
- implement the MessageGroupProcessor
- define my own bean and indicate the aggregation method in my context.
I don't want to use the first one (too coupled to Spring integration framework and I prefer manipulate List<Message<?>> than MessageGroup).
But I face some problem setting my aggregated message's headers.
Code:
public class PayloadAggregator {
public Message<?> aggregate(List<Message<?>> messages) {
StringBuffer buf = new StringBuffer();
for (Message<?> msg : messages) {
buf.append(msg.getPayload());
}
return MessageBuilder.withPayload(buf.toString()).copyHeaders(aggregatedHeaders(messages)).build();
}
private Map<String, ?> aggregatedHeaders(List<Message<?>> messages) {
Map<String, Object> headers = new HashMap<String, Object>();
headers.put("MY_HEADER", "hi");
return headers;
}
}
The point is that the final message does not only contain my customized header, but also other ones coming from my List<Message<?>> to aggregate. Using breakpoints, i saw the the AbstractAggregatingMessageGroupProcessor is called (the CorrelatingMessageHandler use it before calling the MethodInvokingMessageGroupProcessor).
I don't want to use that messageGroupProcessor because it does not fit my needs. Is there any want to desactivate it while using a custom pojo aggregator ?
If I want to fully manage my message headers, am I forced to implement my own MessageGroupProcessor ?
Thanks for your replies