Important Notes for Spring ,Spring boot ,Spring Cloud and Microservices
Ques -1 why dependency name is starter in spring boot?
Ans -it means so many dependency wrap in single dependency. if you don’t want to use starter dependency than you need add 20–30(approx) dependency .
Ques -2 How Resolving conflicts using the dependency tree ?
Right click on pom.xml and Click on showIn and
open terminal and type command
mvn dependency:tree
and see duplicate dependency ..
Ques -3 what is actuator in spring boot ?
Spring Boot provides actuator to monitor and manage our application
Follow the example Git Hub — https://gitlab.com/sanjsingh/actuatorexample
actuator- It provides a hypermedia-based “discovery page” for the other endpoints. It requires Spring HATEOAS to be on the classpath. True
auditevents- It exposes audit events information for the current application. True
autoconfig- It is used to display an auto-configuration report showing all auto-configuration candidates and the reason why they ‘were’ or ‘were not’ applied
beans It is used to display a complete list of all the Spring beans in your application.
configprops It is used to display a collated list of all @ConfigurationProperties. True
dump-It is used to perform a thread dump. True
env-It is used to expose properties from Spring’s ConfigurableEnvironment. True
flyway-It is used to show any Flyway database migrations that have been applied. True
health-It is used to show application health information. False
info-It is used to display arbitrary application info. False
loggers-It is used to show and modify the configuration of loggers in the application. True
liquibase- It is used to show any Liquibase database migrations that have been applied. True
Metrics -It is used to show metrics information for the current application. True
mappings- It is used to display a collated list of all @RequestMapping paths. True
shutdown- It is used to allow the application to be gracefully shutdown. True
/health — Shows application health information
/metrics — Shows ‘metrics’ information for the current application
/trace — Displays trace information (by default the last few HTTP requests)
http://localhost:8999/metrics
http://localhost:8999/beans
management.endpoints.web.exposure.include=*
server.port=8999
Ques-4 How to ignore model class field not create filed in DB (non-persistent attributes) — by using Transient annotation
@Transient
private int port
Ques-5 Naming conflict between model class and database ?
for Example :- String firstName in model class , — — — than table name is first_Name.
You can resolve 2 ways
Case 1 - if you are providing @ Column name annotation
@ Column(name=”firstname”)String firstName
case 2- Hibernate Naming Strategy
spring.jpa.hibernate.naming.physical-strategy=com.devglan.config.CustomPhysicalNamingStrategy);
Spring Data JPA — Reference Documentation — https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#reference
Ques-6 what is use of feign in spring boot ?
By using feign very easy to invoke one micro-services to another ..
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>
follow project in gitLab
Ques -7 why use Ribbon in spring boot ?
Ribbon (Netflix Ribbon) use for client side load balancing.
Ques-8 How to change embebed-tomcat default port using spring boot? [duplicate]
-Dserver.port=8081
Ques 9 — What is Naming Server Or Registry Server (Eureka ) ?
all services register with naming server (Eureka Server )
configuration in naming application and use @EnableEurekaServer
spring.application.name=currancy-naming-server
server.port=8761
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
logging.level=DEBUG
logging.level.org.currancy.exchange.application=ERROR
For Registers client with naming server by using @EnableDiscoveryClient annotation on client application
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
<version>1.4.3.RELEASE</version>
</dependency>
we need to add url into client application.properties file
eureka.client.serviceurl.defaultzone=http://localhost:<naming-server-port>/eureka
ex::: -<naming-server-port> = 8761
Ques -10 What is API Gateways . ??
we need to implement some common feature for every micro-services .
Zuul API Gateway — Zuul acts as an API gateway or Edge service. It receives all the requests coming from the UI and then delegates the requests to internal microservices.
The client calls this service as a proxy for an internal microservice, then this service delegates the request to the appropriate service
The advantage of Zuul API Gateway .
1-it acts like CORS, authentication, and security can be put into a centralized service, so all common aspects will be applied on each request, and if any changes occur in the future, we just have to update the business logic of this Edge Service.
2-we can implement any routing rules or any filter implementation. Say we want to append a special tag into the request header before it reaches the internal microservices, we can do it in the Edge service.
3-As the Edge service itself is a microservice, it can be independently scalable and deployable, so we can perform some load testing, also.
Configuration for Netflix API gateways Server
create zuul proxy application and use annotation @EnableZuulProxy and @EnableDiscoveryClient.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
</dependency>
Now Netflix API gateways Server is ready for use…
Zuul Logging filter Implementation — — — — — -
Netflix zuul example — zuul api gateway pattern — spring cloud tutorial
Ques :11 What is Zipkin and Why use it ..
Zipkin is an open source project that provides mechanisms for sending, receiving, storing, and visualizing traces
Zipkin is Distributed tracing system
Ques:12 what is Spring Cloud Sleuth ?
Spring Cloud Sleuth implements a distributed tracing solution for Spring Cloud, borrowing heavily from Dapper, Zipkin and HTrace. For most users Sleuth should be invisible, and all your interactions with external systems should be instrumented automatically. You can capture data simply in logs, or by sending it to a remote collector service.
Spring Cloud Sleuth implementation
Add dependency into pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
Tracing In Microservices With Spring Cloud Sleuth
flow
application log — — ->RabbitMQ — — -> ZipkinDistributedTracing server (Centralized Logging location)…
Centralized logging for all micro services
Problem
if you are not using Centralized logging then we need to go particular application and check log file.solution of this problem something is called Centralized logging
By using spring cloud -slouth we can solve this problem
it will generate a unique id for all request.and trace all request by unique id.
we can use
Elastic Stack(“ELK” )is the acronym for three open source projects: Elasticsearch, Logstash, and Kibana.
Logstash is a server‑side data processing pipeline that ingests data from multiple sources
simultaneously, transforms it, and then sends it to a “stash”
we can use zipkin server for this .it is provide some UI for log tracing
Rabbitmq Installing on Windows
https://www.rabbitmq.com/install-windows.html
Ques :How Can I check Zipkin Running ?
http://localhost:<port num>/zipkin/
fault tolerance with hystrix .
If I have m1 ,m2 and m3 micro services m1 depend on m2 and m3 .
m2 and m3 not available so by default m1 will not provide actual result it is called fault tolerance.
so we need to improve result by hystrix framework .
How to implement hystrix
Enable
Hibernate State
HTTP Method