简体   繁体   中英

Workflow mechanism for exception and error handling scenarios in Spring Boot or Spring

I am working on design where the requirement is as follows

  1. The application would be built using spring boot
  2. As part of the requirement we would have to build some orchestration where we would end up calling multiple SOAP and REST services and we would perform aggregation, transformation etc.
  3. When an exception/error occurs during the orchestration, we need to capture and persist the state and retry it from the same point where the error occurred.

For example, Lets say there is a Java method in which we have multiple calls to external components say 1 soap call and 2 rest calls ie

String doOrchestration(InputObject obj){

    Line 1: Object obj = soap call[ input is XML format];

    Line 2: Object obj1 = rest1 call [the input is obj in JSON  format]

    Line 3: Object obj3 = rest2 call[the input is obj1 in JOSN  format]

    //do something
    return str

}

The error occurred on Line 2. We need to capture/persist the state and continue the execution from the Line 2 later.

Is there any workflow library, orchestration patterns and/or framework that we can integrate with spring/Spring-boot

Thanks,

well, one tecnology that i use to handle this kind of problems is apache camel, whith camel you can set routes,for instance in your requirement, you can build the main route who will orchest other routes such as yours endpoints, if one endpoint has an exception you can call the route who will persist that and call again the route of the endpoint, or something like that.

http://camel.apache.org/getting-started.html

edit: camel has a lot of potencial transforming messages such as json, xml, objects.

i have a very simple project on github with spring boot and camel if you want to check it.

https://github.com/chill-hub/spring_boot_camel_base_archetype

The Apache Camel version spring like is spring-integration at https://spring.io/projects/spring-integration

Apache Camel and Spring Integration implements enterprise integration pattern called EIP. Please look at https://www.enterpriseintegrationpatterns.com/ first. It is basically design patterns for workflow and orchestration !

You have an integration (starter) with spring boot made by spring named spring-boot-starter-integration.

You should probably look at Java Spring Config dsl reference at https://github.com/spring-projects/spring-integration-java-dsl/wiki/spring-integration-java-dsl-reference which will show you a nice overview, with the more modern approach (xml, and annotation starts to disapear).

With what you need to do you will probably need https://docs.spring.io/spring-integration/reference/html/ws.html which is the web extension for spring integration.

Be careful it is a very elegant solution but with lot of abstraction and can be difficult at the beginning. Keep in mind EIP defines building block and vocabulary to build workflows, Apache Camel and Spring Integration are frameworks that implements these building blocks and offer a threading model abstraction (also queue persistant abstraction), and both have several extensions to adapt easily these building blocks to real word (web, ldap, databases, ...)

Both frameworks are good with pros and cons, but you will probably prefer spring integration in a spring ecosysteme team, same conventions than other spring modules !

Again theses framework are really elegant but abstraction has always a cost!

Disclaimer : I was a trainer for spring integration course - Official

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM