title: Spring Integration Aggregator
body: <p>I want to use an aggregator to create a message out of two messages, but i'm not sure how to do this.</p>
  
  <p>At the moment i'm reading in two files from a directory and want to aggregate those messages into one. </p>
  
  <p>My whole project looks like this:</p>
  
  <p>read in .zip -> pass to custom message handler that unzips it into a directory -> read files from this directory -> try to aggregate them</p>
  
  <p>It would be great if i could send a message with two payloads after unzipping the file, but aggregating after reading it would suffice.</p>
  
  <p>My unzipper looks like this:</p>
  
  <pre><code>public class ZipHandler extends AbstractMessageHandler {
  
  File dat;
  File json;
  
  @Override
  protected void handleMessageInternal(Message&lt;?&gt; message) throws Exception {
      byte[] buffer = new byte[1024];
      try {
          File file = (File) message.getPayload();
          ZipFile zip = new ZipFile(file);
  
          for (Enumeration&lt;? extends ZipEntry&gt; entries = zip.entries(); entries
                  .hasMoreElements();) {
              ZipEntry ze = entries.nextElement();
              String name = ze.getName();
  
              if (name.endsWith(".dat") || name.endsWith(".DAT")) {
                  InputStream input = zip.getInputStream(ze);
                  File datFile = new File("D:/lrtrans/zipOut"
                          + File.separator + name);
                  FileOutputStream fos = new FileOutputStream(datFile);
                  int len;
                  while ((len = input.read(buffer)) &gt; 0) {
                      fos.write(buffer, 0, len);
                  }
                  this.dat = datFile;
                  fos.close();
              } else if (name.endsWith(".json") || name.endsWith(".JSON")) {
                  InputStream input = zip.getInputStream(ze);
                  File jsonFile = new File("D:/lrtrans/zipOut"
                          + File.separator + name);
                  FileOutputStream fos = new FileOutputStream(jsonFile);
                  int len;
                  while ((len = input.read(buffer)) &gt; 0) {
                      fos.write(buffer, 0, len);
                  }
                  this.json = jsonFile;
                  fos.close();
              }
          }
          zip.close();
      } catch (Exception e) {
          e.printStackTrace();
      }
  
  }
  }
  </code></pre>
  
  <p>It takes those files and puts them into two directories, from which i read them in again using FileReadingMessageSource. 
  I also would like to solve this using only annotation based notation, not xml.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I want to just use the defaultAggregatingMessagegroupProcssor with the correlationStrategy based on my header called "zip" and a releaseStrategy based on the message since, in this case two files should be combined into one.</p>
  
  <pre><code>@Aggregator(inputChannel = "toAggregatorChannel", outputChannel = "toRouterChannel", discardChannel = "nullChannel")
  public DefaultAggregatingMessageGroupProcessor aggregate(){
      DefaultAggregatingMessageGroupProcessor aggregator = new DefaultAggregatingMessageGroupProcessor(); 
      return aggregator;
  }
  @CorrelationStrategy 
  public String correlateBy(@Header("zipFile") String zip){
      return zip;
  }
  @ReleaseStrategy
  public boolean isReadytoRelease(List&lt;Message&lt;?&gt;&gt; messages) {
      return messages.size() == 2;
  }
  </code></pre>