views:

39

answers:

1

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;
 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

+1  A: 

The splitter will 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, so you could try out that milestone.

iwein
Can you tell me where to get the nightly snapshot? My understanding is that sftp is there also but i can't find wher eto download it?
Norge
If you use maven you can follow the instructions in a blog I wrote.http://iweinfuld.posterous.com/spring-milestones-and-snapshots-with-mavens3browse has ceased to exist, but you can use a local browser (like cyberduck on mac) with the same effect.
iwein
does it work for you in M7?
iwein