Difference between Springboot 1.X and Springboot 2.X

We have been using Springboot 1.X in our applications and recently started coverting the existing code to use new springboot2.X version. Moving to Spring Boot 2.X will upgrade a number of dependencies hence some of our code needs to be changed. Below are the advantages or new features we came across, 1.Java 8 is minimum version 2.Tomcat 8.5 is minimum version 3.Hibernate 5.2 is minimum version 4.Gradle 3.4 is minimum version 5.Previously several Spring Boot starters were transitively depending on Spring MVC with spring-boot-starter-web. With the new support of Spring WebFlux, spring-boot-starter-mustache, spring-boot-starter-freemarker and spring-boot-starter-thymeleaf are not depending on it anymore. It is the developer’s responsibility to choose and add spring-boot-starter-web or spring-boot-starter-webflux. 6.Spring boot2.X initializr has dedicated auto-configuration to automatically configure the service.The behavior of the spring.config.location configuration has been fixed; it previously added a location to the list of default ones, now it replaces the default locations. If… Read more“Difference between Springboot 1.X and Springboot 2.X”

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.