Chained pattern

The purpose of the chained pattern is to present a more consistent and definitive final response to the client using a chain of services that communicate sequentially. In this way, Service A that acts as a first service in the chain communicate with Service B. Service B communicates with Service C, and so on. The calls are synchronous and the client remains locked until the final response returns from Service A to the client. 

It is important to note here that the requests that arrive at the chain services may be different. In this way, the request sent from Service A to Service B may be very different from the request sent from Service B to Service C, and so on. In the same way, the response of the services may also be different. The response from Service C to Service B may be different from the response from Service B to Service A. 

Let's look at the following diagram:

A practical example of this implementation is the generation of data for the printing of bank slips. Let's suppose that a bank provides two soap web services. One for registering the bank bill data in the bank and the other for getting the bank bill data registered with the bank. Our application contains two defined microservices—Service A, which registers the bank bill data in the data bank (that is, it calls the first registration web service); and Service B, which gets the definitive bank bill data, such as the code bar (meaning that it calls the second query web service), and returns the data for the bank bill generation.

A client application informs the bank data of a user to Service A. Service A is responsible for registering with the banking institution and, with the return of this registration, Service A makes a request to Service B. Service B then gets the definitive data for the generation of the bank bill. Service B passes this data to Service A, and it can then apply some transformation to that data and return it to the client.

This same example can be implemented using the aggregator pattern. However, whenever a sequential order of steps is required to produce a final response, we can think of the chain pattern as a solution.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.165.115