I am using spring cloud kubernetes with spring boot and necessary RBAC requirements needed for the project.
<!-- kubernetes -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-kubernetes</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-kubernetes-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-kubernetes-ribbon</artifactId>
</dependency>
I have 2 microservices running in kubernetes
my-service
some-service
The my-service is running with spring boot 2.x and some-service is running with Spring boot 1.x. Both the services are exposed via the Kubernetes Service and with proper endpoints.
excerpt of application.yaml for my-service is as below.
some-service:
url: http://some-service:8080
serviceName: some-service
And the FeignClient used is as below.
//FeignClient(url = "${some-service.url}") // does not work either
#FeignClient(value = "${some-service.serviceName}")
#RequestMapping("/api")
public interface SomeServiceClient {
Also I have made spring.cloud.kubernetes.discovery.enabled=false
With this in place I expect that my-service should be able to talk to some-service via kubernetes service discovery But I get this error.
ERROR c.b.d.m.s.c.MatchCoordinator - error=FeignException: status 404 reading SomeServiceClient#get(Test
ion,Output) stacktrace=feign.FeignException: status 404 reading SomeServiceClient#get
I am unable to understand what am I doing wrong. Also I do not have the spring.application.name set for some-service since its a third party service.
Can someone please help. Also FYI that the services work properly with port-forwarding and if accessed via Ingress.
If you do not have a name set for some-service, and it's a 3rd party service, I think the better approach would be to call it via RestTemplate or something.
Feign client needs to have the service name configured and known, for it to call that particular service in the network using service discovery.
Well, I found that the discrepancy was at the some-service where the payload of was updated and my-service FeignClient was not updated. and hence caused the HTTP 404 Error. However it works now with the FeignClient properly and able to do a service discovery with the service name properly.
Related
I want to enable actuator for health check in PCF for the non web or batch or commandLineRunner spring boot application.
Could some one please share some details to resolve this issue.
Please let me know if any other details required
I tried the below options
Adding actuator dependency
Adding http and jmx related properties
Since localhost:8081/actuator is not accessible could not view endpoints
How to enable url for non web app
add
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
application.properties
spring.jmx.enabled = true
management.endpoints.jmx.exposure.include=*
management.endpoints.jmx.domain=com.example.demomail
management.endpoints.jmx.unique-names=true
run jconsole find your application name then connect.
find Tab MBeans, find com.example.demomail in left tree.
As far as I understand you need to enable the Actuator endpoints.
You must add the Spring Boot Actuator dependency (as you have already done).
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Then in your application.properties file enable HTTP and JMX support (as you have already done).
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
management.endpoint.jmx.exposure.include=*
Now you will have to push your app to PCF and create a binding to a route to create access for the Actuator endpoint/s.
The URL to access the actuator endpoint will be something like this http://<route-url>/actuator/health
In the command line, I would use something like this to return a list of routes and the URL route of the application.
cf curl /v2/apps/<app-guid>/routes
I am upgrading the spring boot 1.3.7.RELEASE to 2.5.12 and spring framework 5.3.18 in my spring boot microservice based project we have upgrade successfully with all service except gateway service when i am unabling t add zuul dependency because its maintenance mode that why we have implemented spring cloud gateway then i am getting below issue.
***************************
APPLICATION FAILED TO START
***************************
Description:
Spring MVC found on classpath, which is incompatible with Spring Cloud Gateway.
Action:
Please set spring.main.web-application-type=reactive or remove spring-boot-starter-web dependency.
Wwhat we need to do implementation for best way?
We have fix the routing issue using the spring cloud gateway.
Please add dependency in the pom.xml
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-gateway</artifactId> </dependency>
bootstrap.yml
spring:main:web-application-type:reactive
Thanks you guys for supporting.
I have a spring cloud config server configured over spring cloud bus over kafka.
I am using Edgware.RELEASE with boot 1.5.9.
When I send a POST request to the endpoint /bus/refresh with destination=clientId:dev:** in the body via POSTMAN to config server, all the clients get their beans refreshed even though their clientId doesn't match the value in the destination field.
Here are additional configuration details:
spring cloud config server
pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-monitor</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-kafka</artifactId>
</dependency>
application.properties
server.port=8888
management.security.enabled=false
spring.cloud.bus.enabled=true
spring.kafka.bootstrap-servers=localhost:9092
I have two config clients with id - config-client1 and config-client2
After changing an application property in the repository for config-client2, I submit a POST request to /bus/refresh endpoint on the config server, with destination=config-client2:dev:** in the body of the request. I was hoping this would refresh/re-initialize the beans only in config-client2 application. But I noticed beans in config-client application are also refreshed/re-initialized. I also noticed config-client application receiving refresh event along with config-client2.
I was hoping only config-client2 application receives the event and its beans are the only ones that are refreshed as a result of it.
Wondering if I am missing any configuration setting to enable granular refresh at specific client level.
I did go through the document posted at - http://cloud.spring.io/spring-cloud-static/Edgware.RELEASE/single/spring-cloud.html, but the results are not as explained.
Any help with a working example is appreciated.
You can use:
curl -X POST http://localhost:8001/actuator/bus-refresh/config-client2
You also need this in your application.properties or .yml.
spring.cloud.config.uri=http://localhost:8001
spring.cloud.config.uri should point to your Spring Config Server
I'm implementing a Gateway with Zuul. The router is supposed to discover some micro services in order to satisfy the rules described in my application.yml. By default, Zuul is going to leverage Eureka, and this what my application does when starting.
I can read that spring-cloud-consul can be used also: Supports Zuul, a dynamic router and filter via Spring Cloud Netflix. However, there is no clear example that shows how to substitute consul to eureka. I added my dependency to my pom.xml in order to boostrap consul:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
<version>1.0.0.RC1</version>
</dependency>
However, when my application starts, it continues trying to contact eureka (my eureka server is stopped): Can't get a response from http://localhost:8761/eureka/apps/MICROSERVICE-REST-API/xxxxxxx
I'm probably missing some configuration point in order to tell zuul or ribbon to use consul.
Any suggestion?
Thanks
I am trying to make my Spring application as Discovery Client. But the moment I add the following dependency
<dependency>
<groupId>com.netflix.eureka</groupId>
<artifactId>eureka-client</artifactId>
<version>1.1.37</version>
</dependency>
the GWT webapp fails to launch with 503 Service unavailable. Can netflix Eureka be used only with spring boot or spring cloud applications?
Resolved:
The version that I was using was very old. updated the version to 1.1.159 and everything is working fine.