I have a eureka server configured and inside that eureka server I have written a rest api. Now I have a eureka client service and I am trying to call one of the method of eureka service using feign from client service. But I am getting an error "Load balancer does not have available server for client: eureka-service".
But If I call api from a client service to another client service using feign then it is giving successful result. Just can't call API from eureka service.
eureka-service is application name of my eureka server.
#EnableEurekaServer
#SpringBootApplication
public class EurekaApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaApplication.class, args);
}
}
#RestController
#RequestMapping("test")
public class TestController {
#GetMapping
public String test(){
return "test success";
}
}
bootstrap.yml of eureka service
eureka:
client:
registerWithEureka: false
fetchRegistry: false
eureka-server-read-timeout-seconds: 60
eureka-server-connect-timeout-seconds: 60
serviceUrl:
defaultZone: http://localhost:8763/eureka/
dashboard:
enabled: true
spring:
application:
name: eureka-service
And client service is:
#SpringBootApplication
#EnableFeignClients
#EnableDiscoveryClient
public class ClientApplication {
public static void main(String[] args) {
SpringApplication.run(ClientApplication.class, args);
}
}
#FeignClient("eureka-service")
public interface TestFeign {
#GetMapping("test")
String test();
}
bootstrap.yml of client service
eureka:
client:
registerWithEureka: true
fetchRegistry: true
eureka-server-read-timeout-seconds: 60
eureka-server-connect-timeout-seconds: 60
serviceUrl:
defaultZone: http://localhost:8763/eureka/
spring:
application:
name: client-service
feign:
hystrix:
enabled: true
ERROR log : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is com.netflix.hystrix.exception.HystrixRuntimeException: TestFeign#test() failed and no fallback available.] with root cause
com.netflix.client.ClientException: Load balancer does not have available server for client: eureka-service.
How can we solve this issue. Thanks for help in advance.
You need to scan your interfaces that declare they are FeignClients with the #EnableFeignClients annotation in your main class and add the feign.hystrix.enabled=true property.
Related
I have my below app (microservices) which is successfully registered to Eureka server.I t has below Rest end point
#Controller
#RequestMapping("v1/base/")
public class PersonController {
#PostMapping
#RequestMapping(value="/personid")
public ResponseEntity< ?> getPersonList(){
return ResponseEntity.ok("All person list");
}
The properties file for person-application
eureka:
instance:
appname: person-application
client:
enabled: true
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://localhost:8761/eureka/
My zuul server yml file config is is .
server:
port:9000
servlet:
contextPath: /zuulapp
zuul:
routes:
person:
path: /v1/base/**
serviceId: person-application
When i call hit the rest point localhost:9000/zuulapp/person/personid i get the below error.How do i resolve this error
{
"timestamp":"2019-10-08T12:42:09.479+0000",
"status":404,
"error":"Internal Server Error",
"message":"No Message available"
"path" : "/zuulapp/person/personid"
}
Since the registered path in the zuul of the application is "/v1/base/**"
try this one: delete the contextpath properties then replace it with zuul.prefix properties.
server:
port:9000
zuul:
prefix: /zuulapp
routes:
person:
path: /person/**
serviceId: person-application
Now try checking this endpoint:
localhost:9000/zuulapp/person/v1/base/personid
try this in the controller class:
#RestController
#RequestMapping("/v1/base/")
public class PersonController {
#GetMapping(value="/personid")
public ResponseEntity< ?> getPersonList(){
return ResponseEntity.ok("All person list");
}
I fail to understand, nor find any explanation about how can I fix the exception in subject.
This is the main code I use:
Eureka Server
application:
...
#SpringBootApplication
#EnableEurekaServer
public class BbSimApplication {
public static void main(String[] args) {
SpringApplication.run(BbSimApplication.class, args);
}
}
application.yml:
server.port : 8088
spring:
application:
name : bbsim-discovery-server
eureka:
server:
evictionIntervalTimerInMs: 3000
response-cache-update-interval-ms: 3000
wait-time-in-ms-when-sync-empty: 0
peer-node-read-timeout-ms : 10000
client:
registerWithEureka: false
fetchRegistry: false
service-url:
defaultZone: http://localhost:${server.port}/eureka
Controller class:
#RestController
public class WebController {
#Autowired private WebService webService;
#GetMapping("/matchresultbyids")
public MatchStats matchResult(#RequestParam Long homeId, #RequestParam Long awayId){
return webService.matchResult(homeId, awayId);
}
}
Manager Service
application:
#SpringBootApplication
#EnableFeignClients
#EnableDiscoveryClient
public class BBSimManagerServiceApplication {
public static void main(String[] args) {
SpringApplication.run(BBSimManagerServiceApplication.class, args);
}
}
application.yaml:
server.port: 9903
spring:
application.name: bbsim-manager-service
eureka:
client:
serviceUrl:
defaultZone: ${EUREKA_URI:http://localhost:8088/eureka}
registryFetchIntervalSeconds: 1
# register-with-eureka: true
# fetch-registry: true
instance:
leaseRenewalIntervalInSeconds: 1
Client interface:
#FeignClient("match-result-service")
public interface MatchResultClient {
#GetMapping("/matchresultbyids")
MatchStats getMatchResult();
}
Controller class:
#RestController
public class BbsimManagerController {
#Autowired
MatchResultClient matchStatsClient;
#GetMapping("/matchresultbyids")
public MatchStats matchResult(){
return matchStatsClient.getMatchResult();
}
}
MatchResult Service
application:
#SpringBootApplication
#EnableDiscoveryClient
public class MatchResultServiceApplication {
public static void main(String[] args) {
SpringApplication.run(MatchResultServiceApplication.class, args);
}
}
application.yml:
server.port: 9901
spring:
application:
name: match-result-service
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8088/eureka/
registryFetchIntervalSeconds: 1
instance:
leaseRenewalIntervalInSeconds: 1
Controller:
#RestController
public class WebController {
#Autowired private WebService webService;
#GetMapping("/matchresultbyids")
public MatchStats matchResult(){
return webService.matchResult();
}
}
When I try to execute:
http://localhost:9903/matchresultbyids
I get the exception:
o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is feign.FeignException$ServiceUnavailable: [503] during [GET] to [http://match-result-service/matchresultbyids?homeId=0&awayId=1] [MatchResultClient#getMatchResult()]: [Load balancer does not contain an instance for the service match-result-service]] with root cause
feign.FeignException$ServiceUnavailable: [503] during [GET] to [http://match-result-service/matchresultbyids?homeId=0&awayId=1] [MatchResultClient#getMatchResult()]: [Load balancer does not contain an instance for the service match-result-service]
Can you advise me what is wrong and how to fix it?
Thank you all.
It may be related to OpenFeign bug. You can try to upgrade it to the version >= v3.0.6.
If you use spring-cloud-dependencies the version >= v2020.0.5 should be also ok.
I've just started to learn about microservices via spring cloud and to start with I tried to reproduce basic example from this article https://spring.io/blog/2015/07/14/microservices-with-spring. Here is my code:
Eureka server
#SpringBootApplication
#EnableEurekaServer
public class ServiceRegistryApplication {
public static void main(String[] args) {
System.setProperty("spring.config.name", "registration-server");
SpringApplication.run(ServiceRegistryApplication.class, args);
}
}
resources/registration-server.yml:
# Configure this Discovery Server
eureka:
instance:
hostname: localhost
client: # Not a client, don't register with yourself (unless running
# multiple discovery servers for redundancy)
registerWithEureka: false
fetchRegistry: false
server:
port: 1111 # HTTP (Tomcat) port
Sample service:
#SpringBootApplication
#EnableDiscoveryClient
public class AccountsServiceApplication {
public static void main(String[] args) {
System.setProperty("spring.config.name", "accounts-server");
SpringApplication.run(AccountsServiceApplication.class, args);
}
}
accounts-service.yml:
# Spring properties
spring:
application:
name: accounts-service
# Discovery Server Access
eureka:
client:
serviceUrl:
defaultZone: http://localhost:1111/eureka/
# HTTP Server
server:
port: 2222 # HTTP (Tomcat) port
But when I run both apps and go to the localhost:1111 I cannot see my service in the application list:
Could you tel me please what am I doing wrong?
EDIT
After I applied changes the following line appeared:
i have a great solution for you and it's simple
follow those steps:
1- Eureka Server
#SpringBootApplication
#EnableEurekaServer
public class ServiceRegistryApplication {
public static void main(String[] args) {
SpringApplication.run(ServiceRegistryApplication.class, args);
}
}
in application.properties specify those params
spring.application.name=eureka-server
server.port=1111
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
2- in Sample Service
#SpringBootApplication
#EnableDiscoveryClient
public class AccountsServiceApplication {
public static void main(String[] args) {
SpringApplication.run(AccountsServiceApplication.class, args);
}
}
in application.properties specify those params
spring.application.name=accounts-service
server.port=2222
eureka.client.service-url.default-zone=http://localhost:1111/eureka
and don't forget to remove all .yml properties files.
I'm encountering this VIP address null white implementing weightedResponseTimeRule for my Zuul gateway.
Did i do it correctly? implementing a config that will implement weightedRule.
I want to route my request to my 2 or more instance.
Error creating bean with name 'ribbonServerList' defined in org.springframework.cloud.netflix.ribbon.eureka.EurekaRibbonClientConfiguration: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.netflix.loadbalancer.ServerList]: Factory method 'ribbonServerList' threw exception; nested exception is java.lang.NullPointerException: VIP address for client null is null
Currently my Config for Ribbon
#Configuration
public class GatewayRibbonConfiguration {
#Bean
public IClientConfig ribbonClientConfig(){
return new DefaultClientConfigImpl();
}
#Bean
public IPing ribbonPing(IClientConfig config) {
return new PingUrl();
}
#Bean
public IRule ribbonRule(IClientConfig config) {
return new WeightedResponseTimeRule();
}
}
Application
#SpringBootApplication
#EnableDiscoveryClient
#EnableZuulProxy
public class GatewayApplication {
public static void main(String[] args) {
SpringApplication.run(GatewayApplication.class, args);
}
#Bean
public Prefilter prefilter(){
return new Prefilter();
}
}
bootstrap.yml
spring:
application:
name: gateway
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
my properties
server:
port: 8080
hystrix:
command:
default:
execution:
isolation:
thread:
timeoutInMilliseconds: 20000
ribbon:
ReadTimeout: 20000
ConnectTimeout: 20000
zuul:
prefix: /api
ignoredServices: '*'
host:
connect-timeout-millis: 20000
socket-timeout-millis: 20000
routes:
kicks-service:
path: /kicks/**
serviceId: kicks-service
stripPrefix: false
sensitiveHeaders:
kicks-inventory:
path: /inventory/**
serviceId: kicks-inventory
stripPrefix: false
sensitiveHeaders:
I am Exploring Consul for discovery and config server. I have added the required dependencies and yml file is set up. When i try to start the server using spring cloud cli (Spring run .) I am getting the below error which i am unable to resolve. Any help is appreciated.
Error :
"A component required a bean named 'configServerRetryInterceptor' that could >not be found."
I tried to define this bean but when i start the app through spring cloud cli it is not recognizing it.
Please see the code below
App.groovy
#Grab("spring-cloud-starter-consul-config")
#Grab("spring-cloud-starter-consul-discovery")
#EnableDiscoveryClient
#EnableCircuitBreaker
#RestController
#Log
class Application{
#Autowired
Greeter greeter
int counter = 0
#RequestMapping(value = "/counter", produces = "application/json")
String produce() {
counter++
log.info("Produced a value: ${counter}")
"{\"value\": ${counter}}"
}
#RequestMapping("/")
String home() {
"${greeter.greeting} World!"
}
#RequestMapping(value = '/questions/{questionId}')
#HystrixCommand(fallbackMethod = "defaultQuestion")
def question(#PathVariable String questionId) {
if(Math.random() < 0.5) {
throw new RuntimeException('random');
}
[questionId: questionId]
}
def defaultQuestion(String questionId) {
[questionId: 'defaultQuestion']
}
}
#Component
#RefreshScope
class Greeter {
#Value('${greeting}')
String greeting
}
bootstrap.yml
consul:
host: localhost
port: 8500
config:
enabled: true
prefix: config
defaultContext: master
profileSeparator: '::'
format: FILES
discovery:
instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}}
health-check-url: http://127.0.0.1:${server.port}/health
This issue was due to unwanted dependencies being pulled.
Explicitly disabling spring cloud config and spring cloud discovery fixed it.
spring:
cloud:
config:
enabled: false
discovery:
enabled: false
serviceId: CONFIG
eureka:
client:
register-with-eureka: false
fetch-registry: false