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 )”
Category: Spring Boot
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”
How to integrate elastic search with spring boot application
We can use elastic search with spring boot application and for this below are the detailed steps which can be followed. (Please note there some compatibility issue with some version of elastic search hence choose the appropriate one as per your need, I have used the version 2.4.0 with my spring boot app version 1.4.0.RELEASE) 1. Download and unzip the elastic search from http://www.elastic.co/downloads/past-releases/elasticsearch-2-4-0 2. Open config file \elasticsearch-2.4.0\config\elasticsearch.yml and change the cluster name if needed, uncomment and add the value to property 3. Run the elastic search by clicking on batch file, \elasticsearch-2.4.0\bin\elasticsearch.bat (Here this is going to run the elastic search on separate server than your application i.e localhost:9300 ) 4. Add the below dependency to your spring application <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-elasticsearch</artifactId> </dependency> 5. Add the below properties to application.properties file spring.data.elasticsearch.cluster-name= spring.data.elasticsearch.cluster-nodes=localhost:9300 6. To enable the elastic search repository which will be used to save/generate/delete the search… Read more“How to integrate elastic search with spring boot application”
Integration of Rich File Manager with ckeditor
This article is helpful to those developers or programmers who are facing the issues with file upload functionality and are using the ckfinder a paid service. Rich file manager is open source and is free to use. You can follow the below steps to integrate this with ckeditor in your spring boot or java application. 1.Download the latest version of ckeditor and rich file manager. Add the above downloaded files under resources folder of your project. Make sure to add ckeditor and RichFilemanager-master directories in parallel under resource folder. 2.Open the js file /Resources/ckeditor/config.js and add below lines, config.filebrowserImageBrowseUrl =’/RichFilemanager-master/index.html?filter=image’ (Note, we have added the filter Image to support the upload of images only moreover you can remove or modify the filter as per your need. 3. Enabling the java connector – We need to use the java connector to connect rich file manager with ckeditor. i) Modify the rich… Read more“Integration of Rich File Manager with ckeditor”