Closed ghost closed 5 years ago
Seems like the client does not know about this service Load balancer does not have available server for client: user-registation-service
.
This is how services are getting called: zuul --> user-registration-service --> user-search-delete-service All the three servicess are getting resgistred in Eureka client.
I have defined "user-search-delete-service" as a Ribbon client of "user-registration-service". Also used RestTemplate to call "user-search-delete-service" methods from "user-registration-service"
@EnableEurekaClient
@SpringBootApplication
@RibbonClient(name = "user-search-delete-service", configuration = UserSearchDeleteRibbonConfiguration.class)
public class UserRegistrationMicroSrvApplication {
public static void main(String[] args) {
SpringApplication.run(UserRegistrationMicroSrvApplication.class, args);
}
}
@Configuration
class RestTemplateConfig {
// Create a bean for restTemplate to call services
@Bean
@LoadBalanced // Load balance between service instances running at different ports.
public RestTemplate restTemplate() {
return new RestTemplate();
}
}
Do I need to define "user-registration-service" as a Riboon client in zuul service? If yes then can you please let me know why?
Currently Zuul application looks like below:
@SpringBootApplication
@EnableEurekaClient // It acts as a eureka client
@EnableZuulProxy // Enable Zuul
public class ZuulServerApiGatewayApplication {
public static void main(String[] args) {
SpringApplication.run(ZuulServerApiGatewayApplication.class, args);
}
}
Could you please help me to understand what I need to change so that Load balancer can find client: user-registation-service?
I have changed the yml files of all the tree services and mention client:fetch-registry: true also but still it did not work. Can you please help me? Not sure where is the issue.
eureka:
instance:
prefer-ip-address: true
leaseRenewalIntervalInSeconds: 1
leaseExpirationDurationInSeconds: 2
metadata-map:
zone: zone1
instance-id: ${spring.application.name}
client:
prefer-same-zone-eureka: true
register-with-eureka: true
fetch-registry: true
region: region1
service-url:
zone1: http://eureka-server:8761/eureka/
availability-zones:
region1: zone1
healthcheck:
enabled: true
Can you provide a complete, minimal, verifiable sample that reproduces the problem? It should be available as a GitHub (or similar) project or attached to this issue as a zip file.
Eureka Server:
@SpringBootApplication
@EnableEurekaServer
public class UserRegistrationEurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(UserRegistrationEurekaServerApplication.class, args);
}
}
Eureka Application properties:
spring:
application:
name: eureka-server
server:
port: 8761
eureka:
client:
register-with-eureka: false
fetch-registry: false
region: region1
serviceUrl:
zone1: http://eureka-server:8761/eureka/
availability-zones:
region1: zone1
instance:
hostname: eureka-server
metadata-map:
zone: zone1
Zuul:
@SpringBootApplication
@EnableEurekaClient // It acts as a eureka client
@EnableZuulProxy // Enable Zuul
public class ZuulServerApiGatewayApplication {
public static void main(String[] args) {
SpringApplication.run(ZuulServerApiGatewayApplication.class, args);
}
}
Zuul Application properties:
spring:
application:
name: zuul-server
server:
port: 8762
zuul:
ignored-services: '*'
routes:
user-registration-service:
path: /api/**
service-id: user-registation-service
user-registation-service:
ribbon:
eureka:
enabled: true
ServerListRefreshInterval: 1000
ReadTimeout: 60000
ConnectTimeout: 60000
user-search-delete-service:
ribbon:
eureka:
enabled: true
ServerListRefreshInterval: 1000
ReadTimeout: 60000
ConnectTimeout: 60000
hystrix:
command:
user-registation-service:
execution:
isolation:
thread:
timeoutInMilliseconds: 60000
user-search-delete-service:
execution:
isolation:
thread:
timeoutInMilliseconds: 60000
default:
execution:
isolation:
strategy: THREAD
thread:
timeoutInMilliseconds: 600000
eureka:
instance:
prefer-ip-address: true
leaseRenewalIntervalInSeconds: 1
leaseExpirationDurationInSeconds: 2
fetch-registry: true
metadata-map:
zone: zone1
instance-id: ${spring.application.name}:${random.value}
client:
prefer-same-zone-eureka: true
register-with-eureka: true
fetch-registry: true
region: region1
service-url:
zone1: http://eureka-server:8761/eureka/
availability-zones:
region1: zone1
healthcheck:
enabled: true
User Registration Service:
@EnableEurekaClient
@SpringBootApplication
@RibbonClient(name = "user-search-delete-service", configuration = UserSearchDeleteRibbonConfiguration.class)
public class UserRegistrationMicroSrvApplication {
public static void main(String[] args) {
SpringApplication.run(UserRegistrationMicroSrvApplication.class, args);
}
}
@Configuration
class RestTemplateConfig {
// Create a bean for restTemplate to call services
@Bean
@LoadBalanced // Load balance between service instances running at different ports.
public RestTemplate restTemplate() {
return new RestTemplate();
}
}
User Registration application properties:
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://db-server:3306/WEBUSERDB?autoreconnect = true
username: root
password: mandal01
application:
name: user-registation-service
server:
port: 8081
user-search-delete-service:
ribbon:
eureka:
enabled: true
ServerListRefreshInterval: 1000
ReadTimeout: 60000
ConnectTimeout: 60000
eureka:
instance:
prefer-ip-address: true
leaseRenewalIntervalInSeconds: 1
leaseExpirationDurationInSeconds: 2
fetch-registry: true
metadata-map:
zone: zone1
instance-id: ${spring.application.name}:${random.value}
client:
prefer-same-zone-eureka: true
register-with-eureka: true
region: region1
service-url:
zone1: http://eureka-server:8761/eureka/
availability-zones:
region1: zone1
healthcheck:
enabled: true
hystrix:
command:
user-registation-service:
execution:
isolation:
thread:
timeoutInMilliseconds: 60000
user-search-delete-service:
execution:
isolation:
thread:
timeoutInMilliseconds: 60000
default:
execution:
isolation:
strategy: THREAD
thread:
timeoutInMilliseconds: 60000
Calling "User Search Delete" service from "User Registration Service":
Part of controller service:
@RequestMapping(value = "/CreateUser", headers="Content-Type=application/json", method = RequestMethod.POST)
public ResponseEntity<Object> createUser(@RequestBody UserRecord userRecBody ) {
boolean UserIdExists = restTemplate.getForObject("http://user-search-delete-service/SearchUser/"+UserId, boolean.class );
Also there is a "User Search Delete" service. All the services are sperate Spring Boot application and I have dockarisd to run in a seperate containers on bridge network. All the three services are getting registred in Eureka server.
My expectation is, when I am calling "CreateUser" API, Zuul will be able to find "User Registration service". But looks like Zuul is not able to find the service and throwing a "Forwarding error".
Best part is when I am running all the application from the SPring Boot app then its working fine. But when I am running on Containers then getting the issue.
I am now clueless where is the issue.
It should be available as a GitHub (or similar) project or attached to this issue as a zip file.
pasted code isn't helpful.
@spencergibb Please find below the Git Repo Link for the CMV sample. https://github.com/git4suvendu/UserRegistrationApp
My guess is that it has to do with the short intervals for lease renewal and server last refresh. Try extending those and see if that helps.
Changing it to the below values and running. Will give you feedback.
leaseRenewalIntervalInSeconds: 30 leaseExpirationDurationInSeconds: 40
@spencergibb I have changed the lease renewal and expiration intervals. but still getting the issue. Updated Git with changed yml files
@spencergibb Changed ServerListRefreshInterval: 2 but still the same issue. Pls help.
Tried with ServerListRefreshInterval: 60000 but no luck !!
@spencergibb Can you please help to resolve the issue?
Found the issue. There was a typo in the application name in the user registration service yml file.
This is what I am trying to achieve but getting Zuul forwarding error.
If I run the services in Springboot STS at localhost then eveything is working fine. But if I dockarise all the services and run different containers then I am getting Zuul forrwarding error.
Refer the application.yml files in the Github repos.
Could please help? Is it a bug or I am doing something wrong?
Getting the bellow error: