Building and testing customer service

Let's create builds for the Eureka server, customer, and Account service using the mvn clean install command and after that run all these services using the Java command. You can find customer service in port 6161. And Account service is available at port 6060. But we are using the Spring Cloud Eureka registry server, so you don't need to use the actual hostname and port to call Account service in the customer service, just use the logical service name (http://ACCOUNT-SERVICE).

Now fetch the customer service by opening the browser and type http://localhost:6161/customer/1001. It should show the following output in the browser:

As you can see in the preceding screenshot, the customer with the 1001 customer ID has been rendered with two accounts by calling the Account service internally by the customer service. So if both services are running fine, the customer service is displaying the data returned by the Account service. That means the circuit-breaker is in the CLOSED state right now. Now let's move to test the Hystrix circuit-breaker by shutting down the Account service. After shutdown, the Account service and refreshed same URI endpoint as we have opened is at http://localhost:6161/customer/1001.

Let's see the following screenshot after refreshing the browser with the given URI:

This time it will return the fallback method response. Here, Hystrix comes into the picture, it monitors the Account service in frequent intervals and as it is down, the Hystrix component has opened the circuit and enabled the fallback path.

Let's start the Account service again; after a few times, go back to the customer service, and refresh the browser again so you can see the response in normal flow.

Now we will explore how the Hystrix library allows us to customize the default configuration.

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

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