Search code examples
java-8spring-integrationspring-integration-dslspring-integration-sftp

How to customize spring integration flow


I have a requirement like

  1. File comes from FTP
  2. File is copied to local directory
  3. File is picked up
  4. server 1 to parse and read
  5. service 2 to enrich XYZ
  6. service 3 to enrich CDY
  7. service 4 to persist the data in the database and get the set the ids generated (as required later)
  8. service 5 to enrich another piece of information based on service 4
  9. service 6 will send a message to another system
  10. service 7 will update the data again
  11. service 8 will then do something etc
  12. move file back to done directory

At thie point I am thinking about have one flow that will deal with FTP side and get the file and download it.

flow # 02 will pick the file and do the processing as explained above

My question is should I be using the transformers for all these steps above. Also is it ok if I have one flow with all the transformers or should I break it down in sub-flows?.

If any transformer throws an exception will it just ignore the rest of transformers and go to error channel?

Also if I put an exception handling channel will I actually know at which step the exception was thrown?


Solution

  • You really can do everything with transformers if you are not familiar with many other Spring Integration components, like Enricher: https://docs.spring.io/spring-integration/reference/html/message-transformation.html#content-enricher and JPA channel adapters: https://docs.spring.io/spring-integration/reference/html/jpa.html#jpa

    You really can do everything in a single flow even if you are going to have several instances of your application. It is possible to configure a flow the way that every step can be distributed to the whole cluster for even computation. On the other hand I really split my flow to several of them for some logical units.

    If one step throws exception, you indeed don't go downstream with that message any more. This works exactly the same way as regular Java program.

    Yes, starting with some version we add a whole component into an exception message:

    throw IntegrationUtils.wrapInHandlingExceptionIfNecessary(messageToUse,
                    () -> "error occurred in message handler [" + this + "]", e);
    

    Pay attention to this. It will call toString() with a bean name and a configuration source to determine the place from the exception where in the flow an error happened.