Spring Integration @Splitter, what is happening to the header values I have modified?
I have a spring integration splitter with the following method signature:
@Splitter
public List<Message<String[]>> splitCsvIntoSeperateMessages(Message<List<String[]>> message)
The message payload is an ArrayList of String[]. The splitter reads each row in the List, Creates a new Message setting the payload to the data item in the List, adds a CorrelationId, SequenceNumber and SequenceSize to the header and finally returns an ArrayList of Messages.
The problem is that when each individual message is sent to the next channel, the CorrelationId, SequenceNumber and SequenceSize are all overwritten with new values. Is that expected behavior or am I missing something?
Code Snippet Below:
@Splitter
public List<Message<String[]>> splitCsvIntoSeperateMessages(Message<List<String[]>> message) {
List<Message<String[]>> returnVal = new ArrayList<Message<String[]>>();
String headerId = null;
int sequenceSize = 0;
int sequenceNumber = 0;
开发者_Go百科for(String[] payload : message.getPayload()){
if(payload[0].equals("HEAD")){
headerId = UUID.randomUUID().toString();
sequenceSize = Integer.parseInt(payload[payload.length-1]);
sequenceNumber=0;
}
sequenceNumber++;
Message<String[]> msg =
MessageBuilder
.withPayload(payload)
.setCorrelationId(headerId)
.setSequenceSize(sequenceSize)
.setSequenceNumber(sequenceNumber)
.build();
returnVal.add(msg);
}
return returnVal;
}
Using Spring Integration 2.0 M6
Upto 2.0.0.M6 the splitter would set the correlation key, the sequence number and the sequence size by default. We have discussed use cases like nested splitting and you might be able to tag along that discussion.
This feature is added in 2.0.0.M7. The problem should not occur in later versions.
精彩评论