Hystrix (Circuit Breaker )

Hystrix in spring cloud is the implementation of Circuit Breaker pattern, which gives a control over latency and failure between distributed micro services. Here main idea is to stop cascading failures by failing fast and recover as soon as possible. Netflix created Hystrix library implementing the Circuit Breaker pattern to address these kinds of issues. Step1 : Add the Hystrix starter to your spring project <dependency>     <groupId>org.springframework.cloud</groupId>     <artifactId>spring-cloud-starter-netflix-hystrix</artifactId> </dependency> Step2 : Enable the Circuit Breaker by adding annotation to your project @EnableCircuitBreaker Step3 : Now we can use @HystrixCommand annotation on any method we want to apply timeout and fallback method. The fallback method should be defined in the same class and should have the same signature. public class ServiceClient { private final RestTemplate restTemplate; @Autowired     public ServiceClient(RestTemplate restTemplate) {         this.restTemplate = restTemplate;     }     @HystrixCommand(fallbackMethod =… Read more“Hystrix (Circuit Breaker )”

Feign Client

Netflix provides Feign as an abstraction over REST-based calls, by which microservices can communicate with each other, but developers don’t have to bother about REST internal details. 1.Add the feign dependency to your project e.g. <dependency>           <groupId>org.springframework.cloud</groupId>           <artifactId>spring-cloud-starter-feign</artifactId> </dependency> 2.Tell to project that we will use Feign client, so scan its annotation, add the below annotation to your application class @EnableFeignClients 3. Now, we have to create an interface where we declare the services we want to call. Please note that Service Request mapping is same as the Actual Service Rest URL. @FeignClient(name=”MySearch” ) //Service Id of service you want to call public interface MySearchServiceProxy { – – – } 4. Add or create a Controller where we autowire our Feign Interface so Spring can Inject actual implementation during runtime. @RefreshScope @RestController public class FeignMySearchController {    @Autowired    MySearchServiceProxy… Read more“Feign Client”

Why Spring cloud is required?

When we develop microservices with Spring Boot , we might face the below mentioned issues hence spring cloud project helps to eliminate these issues.Spring cloud is set of tools to manage and establish the service Discovery, config management and Circuit Breakers etc. It manages and handles following very efficiently, 1. Any of the network and security issues. 2. Service discovery tools manage how processes and services in a cluster can find and talk to one another. It involves a directory of services, registering services in that directory, and then being able to lookup and connect to services in that directory. 3. Redundancy issues in distributed systems. 4. Load balancing improves the distribution of workloads across multiple computing resources, such as computers, a computer cluster, network links, central processing units, or disk drives. 5. Performance issues due to various operational overheads. 6. Requirement of deployment and continuous integration.

Microservices and their key benefits

Microservices are a kind of software architectural solution that allows software to be developed into relatively small, distinct and loosely coupled components. Each of the components provides a distinct subset of the functionality of the entire application. Each microservice, can then be designed, developed, and managed independently. This allows for distributed ownership of a large application across a large organisation, with each microservice owned by a specific team. Microservices are an independent components and are smaller in size hence can be easily built and maintain by a small team. Microservices are scalable. Technology diversity i.e. This eliminates long-term commitment to a single technology stack, if you want to try out a new technology stack on an individual service, you can go ahead. Fault isolation i.e. larger applications remain unaffected by the failure of small component. Better support for parallel team to work on separate components. Independent deployment and easy integration…. Read more“Microservices and their key benefits”