load balancer does not have available server for client: provider

Ask Question

up vote6down votefavorite

4

I‘m trying to use Feign client. Below is my feing client:

import com.eprogrammerz.examples.domain.Movie;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * Created by Yogen on 12/26/2016.
 */
@FeignClient(name = "movie-api")
public interface MovieApi {
    @RequestMapping(method = RequestMethod.GET, value = "/movies/{id}")
    Movie getMovie(@PathVariable("id") Long id);
}

I‘m calling it from simple service as below:

@Service
public class MovieService {

    @Autowired
    MovieApi movieApi;

    public Movie findMovie(Long id){
        Movie movieOfTheDay = movieApi.getMovie(id);
        return movieOfTheDay;
    }
}

My spring boot app is as below:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.feign.EnableFeignClients;

@EnableFeignClients(basePackages = {"com.eprogrammerz.examples"})
@EnableCircuitBreaker
@SpringBootApplication
public class ClientAppApplication {

    public static void main(String[] args) {
        SpringApplication.run(ClientAppApplication.class, args);
    }
}

build.gradle

buildscript {
    ext {
        springBootVersion = ‘1.4.3.RELEASE‘
    }
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: ‘java‘
apply plugin: ‘eclipse‘
apply plugin: ‘org.springframework.boot‘

jar {
    baseName = ‘client-app‘
    version = ‘0.0.1-SNAPSHOT‘
}
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    jcenter()
    mavenCentral()
    maven { url "https://repo.spring.io/snapshot" }
    maven { url "https://repo.spring.io/milestone" }
}

dependencies {
    compile(‘org.springframework.cloud:spring-cloud-starter-feign‘)
    // https://mvnrepository.com/artifact/com.netflix.hystrix/hystrix-core
    compile(‘org.springframework.cloud:spring-cloud-starter-hystrix‘)
    compile("org.springframework.boot:spring-boot-starter-web"){
        exclude group: ‘org.springframework.boot‘, module: ‘spring-boot-starter-logging‘
    }
    compileOnly(‘org.projectlombok:lombok‘)
    testCompile(‘org.springframework.boot:spring-boot-starter-test‘)
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:Camden.BUILD-SNAPSHOT"
        mavenBom "org.springframework.boot:spring-boot-starter-parent:${springBootVersion}"
    }
}

I‘m getting error as below:

2016-12-30 13:07:16.894  INFO 6748 --- [nio-8082-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet ‘dispatcherServlet‘: initialization completed in 39 ms
2016-12-30 13:07:16.939  INFO 6748 --- [nio-8082-exec-1] c.e.e.controllers.RequestController      : Calling findMovie(1203)
2016-12-30 13:07:17.240  INFO 6748 --- [rix-movie-api-1] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.[email protected]: startup date [Fri Dec 30 13:07:17 EST 2016]; parent: org.springframework.boot.context.embedded.[email protected]
2016-12-30 13:07:17.318  INFO 6748 --- [rix-movie-api-1] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 ‘javax.inject.Inject‘ annotation found and supported for autowiring
2016-12-30 13:07:17.619  INFO 6748 --- [rix-movie-api-1] c.netflix.config.ChainedDynamicProperty  : Flipping property: movie-api.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
2016-12-30 13:07:17.670  INFO 6748 --- [rix-movie-api-1] c.n.u.concurrent.ShutdownEnabledTimer    : Shutdown hook installed for: NFLoadBalancer-PingTimer-movie-api
2016-12-30 13:07:17.727  INFO 6748 --- [rix-movie-api-1] c.netflix.loadbalancer.BaseLoadBalancer  : Client:movie-api instantiated a LoadBalancer:DynamicServerListLoadBalancer:{NFLoadBalancer:name=movie-api,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:null
2016-12-30 13:07:17.739  INFO 6748 --- [rix-movie-api-1] c.n.l.DynamicServerListLoadBalancer      : Using serverListUpdater PollingServerListUpdater
2016-12-30 13:07:17.746  INFO 6748 --- [rix-movie-api-1] c.n.l.DynamicServerListLoadBalancer      : DynamicServerListLoadBalancer for client movie-api initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=movie-api,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:com.netflix.loadbalancer.[email protected]2016-12-3013:07:18.191 ERROR 6748---[nio-8082-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]:Servlet.service()for servlet [dispatcherServlet]in context with path [] threw exception [Request processing failed; nested exception is com.netflix.hystrix.exception.HystrixRuntimeException:MovieApi#getMovie(Long) failed and no fallback available.] with root cause

com.netflix.client.ClientException:Load balancer does not have available server for client: movie-api
    at com.netflix.loadbalancer.LoadBalancerContext.getServerFromLoadBalancer(LoadBalancerContext.java:468)~[ribbon-loadbalancer-2.2.0.jar:2.2.0]
    at com.netflix.loadbalancer.reactive.LoadBalancerCommand$1.call(LoadBalancerCommand.java:184)~[ribbon-loadbalancer-2.2.0.jar:2.2.0]
    at com.netflix.loadbalancer.reactive.LoadBalancerCommand$1.call(LoadBalancerCommand.java:180)~[ribbon-loadbalancer-2.2.0.jar:2.2.0]
    at rx.Observable.unsafeSubscribe(Observable.java:10211)~[rxjava-1.1.10.jar:1.1.10]
    at rx.internal.operators.OnSubscribeConcatMap.call(OnSubscribeConcatMap.java:94)~[rxjava-1.1.10.jar:1.1.10]
    at rx.internal.operators.OnSubscribeConcatMap.call(OnSubscribeConcatMap.java:42)~[rxjava-1.1.10.jar:1.1.10]
    at rx.Observable.unsafeSubscribe(Observable.java:10211)~[rxjava-1.1.10.jar:1.1.10]
    at rx.internal.operators.OperatorRetryWithPredicate$SourceSubscriber$1.call(OperatorRetryWithPredicate.java:127)~[rxjava-1.1.10.jar:1.1.10]
    at rx.internal.schedulers.TrampolineScheduler$InnerCurrentThreadScheduler.enqueue(TrampolineScheduler.java:73)~[rxjava-1.1.10.jar:1.1.10]
    at rx.internal.schedulers.TrampolineScheduler$InnerCurrentThreadScheduler.schedule(TrampolineScheduler.java:52)~[rxjava-1.1.10.jar:1.1.10]
    at rx.internal.operators.OperatorRetryWithPredicate$SourceSubscriber.onNext(OperatorRetryWithPredicate.java:79)~[rxjava-1.1.10.jar:1.1.10]
    at rx.internal.operators.OperatorRetryWithPredicate$SourceSubscriber.onNext(OperatorRetryWithPredicate.java:45)~[rxjava-1.1.10.jar:1.1.10]
    at rx.internal.util.ScalarSynchronousObservable$WeakSingleProducer.request(ScalarSynchronousObservable.java:276)~[rxjava-1.1.10.jar:1.1.10]
    at rx.Subscriber.setProducer(Subscriber.java:209)~[rxjava-1.1.10.jar:1.1.10]
    at rx.internal.util.ScalarSynchronousObservable$JustOnSubscribe.call(ScalarSynchronousObservable.java:138)~[rxjava-1.1.10.jar:1.1.10]
    at rx.internal.util.ScalarSynchronousObservable$JustOnSubscribe.call(ScalarSynchronousObservable.java:129)~[rxjava-1.1.10.jar:1.1.10]
    at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)~[rxjava-1.1.10.jar:1.1.10]
    at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)~[rxjava-1.1.10.jar:1.1.10]
    at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)~[rxjava-1.1.10.jar:1.1.10]
    at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)~[rxjava-1.1.10.jar:1.1.10]
    at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)~[rxjava-1.1.10.jar:1.1.10]
    at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)~[rxjava-1.1.10.jar:1.1.10]
    at rx.Observable.subscribe(Observable.java:10307)~[rxjava-1.1.10.jar:1.1.10]
    at rx.Observable.subscribe(Observable.java:10274)~[rxjava-1.1.10.jar:1.1.10]
    at rx.observables.BlockingObservable.blockForSingle(BlockingObservable.java:445)~[rxjava-1.1.10.jar:1.1.10]
    at rx.observables.BlockingObservable.single(BlockingObservable.java:342)~[rxjava-1.1.10.jar:1.1.10]
    at com.netflix.client.AbstractLoadBalancerAwareClient.executeWithLoadBalancer(AbstractLoadBalancerAwareClient.java:102)~[ribbon-loadbalancer-2.2.0.jar:2.2.0]
    at org.springframework.cloud.netflix.feign.ribbon.LoadBalancerFeignClient.execute(LoadBalancerFeignClient.java:63)~[spring-cloud-netflix-core-1.2.4.BUILD-SNAPSHOT.jar:1.2.4.BUILD-SNAPSHOT]
    at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:97)~[feign-core-9.3.1.jar:na]
    at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:76)~[feign-core-9.3.1.jar:na]
    at feign.hystrix.HystrixInvocationHandler$1.run(HystrixInvocationHandler.java:108)~[feign-hystrix-9.3.1.jar:na]
    at com.netflix.hystrix.HystrixCommand$2.call(HystrixCommand.java:301)~[hystrix-core-1.5.6.jar:1.5.6]
    at com.netflix.hystrix.HystrixCommand$2.call(HystrixCommand.java:297)~[hystrix-core-1.5.6.jar:1.5.6]
    at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:46)~[rxjava-1.1.10.jar:1.1.10]
    at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:35)~[rxjava-1.1.10.jar:1.1.10]
    at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)~[rxjava-1.1.10.jar:1.1.10]
    at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)~[rxjava-1.1.10.jar:1.1.10]
    at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)~[rxjava-1.1.10.jar:1.1.10]
    at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)~[rxjava-1.1.10.jar:1.1.10]
    at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)~[rxjava-1.1.10.jar:1.1.10]
    at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)~[rxjava-1.1.10.jar:1.1.10]
    at rx.Observable.unsafeSubscribe(Observable.java:10211)~[rxjava-1.1.10.jar:1.1.10]
    at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:51)~[rxjava-1.1.10.jar:1.1.10]
    at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:35)~[rxjava-1.1.10.jar:1.1.10]
    at rx.Observable.unsafeSubscribe(Observable.java:10211)~[rxjava-1.1.10.jar:1.1.10]
    at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:41)~[rxjava-1.1.10.jar:1.1.10]
    at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:30)~[rxjava-1.1.10.jar:1.1.10]
    at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)~[rxjava-1.1.10.jar:1.1.10]
    at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)~[rxjava-1.1.10.jar:1.1.10]
    at rx.Observable.unsafeSubscribe(Observable.java:10211)~[rxjava-1.1.10.jar:1.1.10]
    at rx.internal.operators.OperatorSubscribeOn$1.call(OperatorSubscribeOn.java:94)~[rxjava-1.1.10.jar:1.1.10]
    at com.netflix.hystrix.strategy.concurrency.HystrixContexSchedulerAction$1.call(HystrixContexSchedulerAction.java:56)~[hystrix-core-1.5.6.jar:1.5.6]
    at com.netflix.hystrix.strategy.concurrency.HystrixContexSchedulerAction$1.call(HystrixContexSchedulerAction.java:47)~[hystrix-core-1.5.6.jar:1.5.6]
    at com.netflix.hystrix.strategy.concurrency.HystrixContexSchedulerAction.call(HystrixContexSchedulerAction.java:69)~[hystrix-core-1.5.6.jar:1.5.6]
    at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)~[rxjava-1.1.10.jar:1.1.10]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)~[na:1.8.0_51]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)~[na:1.8.0_51]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)~[na:1.8.0_51]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)~[na:1.8.0_51]
    at java.lang.Thread.run(Thread.java:745)[na:1.8.0_51]

I tried different way. But couldn‘t figure out the solution. I couldn‘t find any information about this on Spring Cloud Netflix too. I couldn‘t find any information on discussion thread on StackOverflow too.

What I‘m missing here? TIA.

Further Details:

application.yml for movie-api microservice is as below:

server:
  port: 8090
logging:
  config: classpath:log4j2.yml
spring:
  application:
    name: movie-api

Spring boot app on movie-api module:

@SpringBootApplication
public class MovieApiApplication {

    public static void main(String[] args) {
        SpringApplication.run(MovieApiApplication.class, args);
    }
}

And controller is as below:

@RestController
@Slf4j
public class MovieController {
    @Autowired
    private MovieRepository movieRepository;

    @RequestMapping("/movies/{id}")
    public ResponseEntity<Movie> getBook(@PathVariable("id") Long id){
        log.trace("getBook({})",id);
        Optional<Movie> movie = Optional.of(movieRepository.findOneById(id));
        if(movie.isPresent())
            return new ResponseEntity(movie.get(), HttpStatus.OK);
        return new ResponseEntity<Movie>(HttpStatus.NOT_FOUND);
    }
}

spring spring-boot spring-cloud-netflix netflix-feign

shareimprove this question

edited May 23 ‘17 at 10:31

Community

11

asked Dec 30 ‘16 at 18:35

Yogen Rai

8452721

  • 1

    Are you using a service discovery such as Eureka or Consul? If so, have you defined the configuration in your Spring Boot app‘s application.yml to register the app as a client to Eureka? Basically, Feign is complaining that it could not find the service registered anywhere. You can very easily configure a service discovery like Eureka using Spring Cloud. See projects.spring.io/spring-cloud – Bloodysock Dec 30 ‘16 at 22:37

  • 1

    @Bloodysock so on which side should i use discovery service? Here on client side or api side? – Yogen RaiJan 1 ‘17 at 2:09

  • 1

    You‘d register your API (better term would be "service") with a unique name to the service discovery. The client simply discovers the service and invokes it. Spring Cloud makes it real easy for the developer especially with Spring Boot. Go through the example documented at the site I linked above. You will on your way making the service calls in 15 minutes :) – Bloodysock Jan 1 ‘17 at 16:04

  •  

    @Bloodysock yes you are right! i was missing ‘service‘ registration. Thank you!. – Yogen Rai Jan 3 ‘17 at 6:44

add a comment

3 Answers

activeoldestvotes

up vote14down voteaccepted

After doing research, and with help of @Bloodysock, I found that I was missing registration of remote server in ‘client-app‘ micro-service. The document is at Spring Cloud Netflix.

I used Ribbon without Eureka with configuration in application.yml in ‘client-app‘ micro-service as:

movie-api:
  ribbon:
    listOfServers: http://localhost:8090

shareimprove this answer

answered Jan 3 ‘17 at 6:56

Yogen Rai

8452721

add a comment

up vote1down vote

The problem is that your service doesn‘t know the host of requested service. If you are using Eureka, put this line on your .properties or .yml file:

eureka.client.fetchRegistry=true

OR

eureka: client: fetchRegistry: true

It‘ll make your service talk with Eureka and discovers host of requested service.

shareimprove this answer

answered Mar 21 at 18:08

Luciano Nery

163

add a comment

up vote0down vote

If you Spring Cloud set up does not support specifying the servers in application.properties/application.yml, you have to configure the services URL in a Configuration class.

Pls, note the warning message in my application.properties [Spring Boot v2.0.0RELEASE, spring-cloud-starter-feign & spring-cloud-starter-ribbon v 1.4.3.RELEASE]

So what I did was to write a Configuration class as follows:

@Configuration
class LocalRibbonClientConfiguration {
    @Bean
    public ServerList<Server> ribbonServerList() {
        // return new ConfigurationBasedServerList();
        StaticServerList<Server> staticServerList = new StaticServerList<>((new Server("localhost", 8001)),
                new Server("localhost", 8000));
        return staticServerList;
    }
}

Then, configured the Spring Boot Application to use this configuration as follows:

@SpringBootApplication
@EnableFeignClients("my-package.currencyconversionservice")
@RibbonClient(name = "currency-conversion-service", configuration = LocalRibbonClientConfiguration.class)
public class CurrencyConversionServiceApplication {
 // nothing new here...
}

No need to change the Feign Proxy class. Posting just for this post to be served as a complete solution to the problem:

@FeignClient(name="currency-exchange-service")
@RibbonClient(name="currency-exchange-service")
public interface CurrencyExchangeServiceProxy {
    @GetMapping("/currency-exchange/from/{from}/to/{to}")
    public CurrencyConversionBean retrieveExchangeValue(@PathVariable("from") String from, @PathVariable("to") String to);
}

That‘s all. The problem was fixed.

shareimprove this answer

answered Mar 13 at 5:32

Dexter

1,27711729

add a comment

原文地址:https://www.cnblogs.com/lykbk/p/dfgfdgdfdg546546456.html

时间: 2024-11-05 22:39:00

load balancer does not have available server for client: provider的相关文章

Load balancer does not have available server for client

最近在研究spring-cloud,研究zuul组件时发生下列错误: Caused by: com.netflix.client.ClientException: Load balancer does not have available server for client: zuul-server 解决办法就是在pom文件里添加 <dependency> <groupId>org.springframework.cloud</groupId> <artifact

Feign报错Caused by: com.netflix.client.ClientException: Load balancer does not have available server for client

问题描述 使用Feign调用微服务接口报错,如下: java.lang.RuntimeException: com.netflix.client.ClientException: Load balancer does not have available server for client: app1 at org.springframework.cloud.netflix.feign.ribbon.LoadBalancerFeignClient.execute(LoadBalancerFeig

com.netflix.client.ClientException: Load balancer does not have available server for client xxxx

版本spring boot: 2.0.1.RELEASE spring cloud: Finchley.M9 错误通过zuul调用eureka注册的服务,错误内容如下 Caused by: com.netflix.client.ClientException: Load balancer does not have available server for client xxxxx 方案经过查询排查,两种解决方案 方案一(亲测有效) 在application.properties中添加 ribb

com.netflix.client.ClientException: Load balancer does not have available server for client: provider-user

在使用feign远程调用的时候启动项目报错. 报错信息如下: com.netflix.client.ClientException: Load balancer does not have available server for client:xxx 解决方法: 在客户端 (消费者) 的application.yml文件中添加以下配置即可 ribbon: eureka: enabled: true 原文地址:https://www.cnblogs.com/jack-zhou21235/p/12

com.netflix.client.ClientException: Load balancer does not have available server for client:xxx

重启一个web模块,刷新页面报错, 负载均衡器没有可用的服务器给客户端:在网关添加. 1 ribbon: 2 eureka: 3 enabled: true 原文地址:https://www.cnblogs.com/yz0812/p/10195066.html

负载均衡server load balancer

负载均衡(Server Load Balancer,简称SLB)是对多台云服务器进行流量分发的负载均衡服务.SLB可以通过流量分发扩展应用系统对外的服务能力,通过消除单点故障提升应用系统的可用性. (与cdn关系,cdn用到了负载均衡,CDN 利用全局负载均衡技术将用户的访问指向离用户最近的工作正常的流媒体服务器上,由流媒体服务器直接响应用户的请求.服务器中如果没有用户要访问的内容,会根据配置自动从原服务器抓取相应的内容并提供给用户. IPTV 可利用 CDN 为用户提供 VOD 业务,通过 C

Neutron 理解 (7): Neutron 是如何实现负载均衡器虚拟化的 [How Netruon Implements Load Balancer Virtualization]

学习 Neutron 系列文章: (1)Neutron 所实现的虚拟化网络 (2)Neutron OpenvSwitch + VLAN 虚拟网络 (3)Neutron OpenvSwitch + GRE/VxLAN 虚拟网络 (4)Neutron OVS OpenFlow 流表 和 L2 Population (5)Neutron DHCP Agent (6)Neutron L3 Agent (7)Neutron LBaas 1. 基础知识 1.1 负载均衡的概念 负载均衡(Load Balan

OVN实战---《The OVN Load Balancer》翻译

Overview 基于前面几篇文章的基础之上,我们接下来将要探索OVN中的load balancingz这一特性.但是在开始之前,我们先来回顾一下上一个lab中创建好的拓扑结构. The lab network The OVN logical network The OVN Load Balancer The OVN load balancer用于为OVN逻辑网络空间中的负载提供基本的负载均衡的功能.由于它的简单特性,它并不是用来替代基于应用的,专有的load balancer,后者往往提供了更

Docker : Tomcat Clustering with Load Balancer (Tomcat and Nginx)

Tomcat Clustering Series Part 5 : NginX as Load Balancer - Ramki Technical Bloghttps://www.ramkitech.com/2013/01/tomcat-clustering-series-part-5-nginx.html Docker : Tomcat Clustering with Load Balancer (Tomcat and Nginx) - Ramki Technical Bloghttps:/