Search code examples
javarestweb-servicesdesign-patternsmicroservices

Design pattern to use when multiple calls to the webservices are done


I am developing a microservice which calls 4 different soap webservices one after the other and response of each soap service is fed as the input request to the subsequent soap webservice. The scenario is explained as below:

micrservice
|------------------> soap service 1
       if(soap_Service1_Response.indicator is 1)
        {
                 call soap webservice 2(responseOfsoapService1)
         }
        else if(soap_Service1_Response.indicator is 2)
        {
                call soap webservice 3(responseOfsoapService2)
        }
         ........and so on.

Which design pattern to use in this scenario so that multiple if and else need not to be written? Thanks in advance


Solution

  • One way could be the Chain of Responsibility

    You have a processor object which has a reference to next processor. The first processor runs the request and passes the result to the next processor which runs next request and passes its result to next processor and so on.