title: Spring Integration - Filter - Send messages to a different end point
body: <p>My input is a csv file as given below:</p>
  
  <pre><code>USER_ID, USER_NAME, FREQUENCY, FREQUENCY_DETAIL
  A123, AAA, ANNUALLY, 1-JUN
  B123, BBB, INVALID_FREQUENCY, 21-JUN
  C123, CCC, ANNUALLY, APR
  D123, DDD, WEEKLY, 1-DEC
  </code></pre>
  
  <p>Validations:</p>
  
  <pre><code>USER_ID -&gt; alphanumeric
  USERNAME -&gt; alphabets only
  FREQUENCY -&gt; must be one of DAILY, WEEKLY, MONTHLY , ANNUALLY
  FREQUENCY DETAIL -&gt; Pattern \\d{1,2}-\\w{3}
  </code></pre>
  
  <p>My Bean is as follows:</p>
  
  <pre><code>class UserBean {
      String userID;
      String userName;
      String frequency;
      String frequencyDetail;
  
      String status = "SUCCESS"; //Code generated. If any of the above fields is not valid, set as "ERROR, &lt;field that failed&gt;". E.g.: ERROR, FREQUENCY_DETAIL
  }
  </code></pre>
  
  <p>My flow is as follows:</p>
  
  <ol>
  <li>Read csv file from folder</li>
  <li>Convert to UserBean (using openCsv)</li>
  <li>If the status of any of the beans contains "ERROR", write to a separate channel called "errorSummaryReportChannel".</li>
  </ol>
  
  <p>This channels writes userID + status to a file.</p>
  
  <p><strong><em>4. For all beans (with status = "SUCCESS" or status = "ERROR"), convert to JSON and log output.</em></strong></p>
  
  <p><strong><em>WHERE I NEED HELP:</em></strong> </p>
  
  <p>Step 3</p>
  
  <p>If the userBean has status = "ERROR", write to  "errorSummaryReportChannel".
  For all status, proceed with normal flow.</p>
  
  <p>I think an output channel &amp; discard channel must be added, but could not find any example.</p>
  
  <p>My code:</p>
  
  <pre><code>@Configuration
  public class CreateUserConfiguration {
      @Bean
      public IntegrationFlow createUser() {
          return IntegrationFlows.from(Files.inboundAdapter(new File(INPUT_DIR)))
                  .enrichHeaders(h -&gt; h.header("errorChannel", "exceptionChannel", true))
                  .transform(csvToUserBeanTransformer, "convertCsvToUserBean")
                  .split(userBeanSplitter, "splitUserBeans")
                  .wireTap(flow -&gt; flow.&lt;PrimeAOBean&gt;filter(primeAOBean -&gt; primeAOBean.getStatus().equalsIgnoreCase("SUCCESS"), errorFlow -&gt; errorFlow.discardChannel("errorSummaryReportGenerationChannel")))
                  .transform(userBeanToJSONTransformer, "convertUserBeanToJSON")
                  .handle(Files.outboundAdapter(new File(OUTPUT_SUCCESS_DIRECTORY)))
                  .get();
      }
  
      @Bean
      public IntegrationFlow logErrorSummary() {
          return IntegrationFlows.from("errorSummaryReportGenerationChannel")
                  .handle((p,h) -&gt; {
                      return ((UserBean)(p)).getUserID() + "\t" + ((UserBean)(p)).getStatus();
                  })
                  .transform(Transformers.objectToString())
                  .handle(Files.outboundAdapter(new File(OUTPUT_FAILED_REPORT_FILE_NAME)))
                  .get();
      }
  
  @Bean
  public IntegrationFlow logError() {
      return IntegrationFlows.from("exceptionChannel")
              .enrichHeaders(h -&gt; h.headerExpression("errorFileName", "payload.failedMessage.headers.fileName"))
              .transform(Transformers.toJson())
              .handle(Files.outboundAdapter(new File(generateOutputDirectory(OUTPUT_FAILED_DIRECTORY))))
              .get();
  }
  
  }
  </code></pre>
  
  <p>Can someone please help?</p>