implement circuit breaker with openfeign in spring-boot 2.4 and spring cloud 2020 - spring

If I want to upgrade to spring-boot 2.4 and spring cloud 2020.
Now that spring-cloud-starter-netflix-hystrix has been removed from spring-cloud-netflix,
How can I implement circuit breaker with openfeign?
I did a direct import but my IDE cannot resolve feign.hystrix.enabled and feign is not executing the fallback class.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>2.2.7.RELEASE</version>
</dependency>

Related

Zipkin server is not showing Microservices trace

I have a Microservice A calling another Microservice B with the following pom.xml and application.properties values:
pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
</dependency>
application.properties
spring.zipkin.base-url=http://localhost:9411/
spring.sleuth.sampler.probability=1.0
spring.zipkin.sender.type=web
spring.zipkin.collector.http.enabled=true
Zipkin server version: zipkin-server-2.12.9
Spring Boot Version: 2.7.5
Spring cloud version: 2021.0.4
Issue is that trace that Microservice A called Microservice B with the trace-ID is not getting displayed in Zipkin.
Any issue?
Trace of Microservices calling chain with trace-ID should be coming in Zipkin server
The problem was that RestTemplate used to call the another service was create as New.
Solution is that create it as a bean and inject it to your code.

Springboot disable selected prometheus metrics

I am using springboot gateway 2.0.4.RELEASE.
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
After adding this dependency, it is exposing all metrics to prometheus endpoint.
I want to disable some of the metrics from exposing through /actuator/prometheus endpoint.
Let's say I want to disable
gateway_requests_seconds_count
gateway_requests_seconds_sum
gateway_requests_seconds_max
Does anyone know how can I achieve this ?
Thanks
Alpesh

Spring boot Kubernetes Service Discovery

I am running into issues with Kubernetes Service Discovery on Spring Boot applications.
I should be able to discover the services whether my spring boot application is running within or out of Kubernetes cluster. Our local development won't be on k8s cluster.
I am using Service Discovery via DNS. I tried using spring-cloud-starter-kubernetes
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-kubernetes</artifactId>
<version>0.2.0.RELEASE</version>
</dependency>
As per documentation you should be able to autowire DiscoveryClient and good to go
#Autowire
private DiscoveryClient discoveryClient;
DiscoveryClient is part of spring-cloud-commons. spring-cloud-starter-kuberenetes doesn't have it.
Anyone solved similar problem using the same library or a different one? Please share the solution
Thanks!
I have solved this issue using the Spring Cloud Kubernetes Dependencies
<spring.cloud.kubernetes>0.2.0.RELEASE</spring.cloud.kubernetes>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-kubernetes-ribbon</artifactId>
<version>${spring.cloud.kubernetes}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-kubernetes-config</artifactId>
<version>${spring.cloud.kubernetes}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-kubernetes-core</artifactId>
<version>${spring.cloud.kubernetes}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-kubernetes-discovery</artifactId>
<version>${spring.cloud.kubernetes}</version>
</dependency>
What was very important for me was the ribbon dependency as it makes use of a load balanced rest template in order to substitute service names for the correct pod IP's that are found in your kubernetes cluster.
I have created a git repo as part of answering a larger set of questions but it should be more than sufficient if someone is looking a way to implement Kubernetes service discovery in place of Eureka or Consul.
https://github.com/foundery-rmb/kubernetes-service-discovery

How to use zuul in spring cloud without spring boot actuator?

I want to use zuul as a proxy server in my application, but I don't want to use spring boot actuator, I tried to remove it from the dependency as follow:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
<version>${spring-cloud-netflix.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</exclusion>
</exclusions>
</dependency>
However, it will cause some ClassNotFoundException.
I don't need spring boot actuator in my application, but it has so many autoconfiguration in spring boot that will produce many endpoints that I don't want.
Is there any good way to solve this?
The issue has been addressed in spring cloud netflix 1135. It will be available shortly in Brixton.SR2.

How to add Spring Boot Actuator to a Spring application?

In the "Bootiful" Applications with Spring Boot Spring One 2014 section(https://www.youtube.com/watch?v=HCyYEVRZISk), Josh mentioned that it is easy to add the Boot Actuator to a Spring (non-bootiful) application. I assume that an Actuator configuration is needed somehow, but can't find how it shall be done.
Just add the starter to your pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
... and the endpoints such as /health will be available.

Resources