我正在使用功能区客户端进行客户端负载平衡。我正在实施微服务Spring启动 2.2.6.发布。我有CHAT-BOOK和USER-APP两个微服务。我在 CHAT-BOOK 中添加了所需的依赖项(spring-boot-starter-web,spring-cloud-starter-netflix-ribbon)中的 USER-APP 微服务.xml。
CHAT-BOOK microservice:
@RestController
@RequestMapping("/chatbook")
public class ChatbookController {
@Value("${server.port}")
private String port;
@GetMapping("/chatnow")
public String chat() {
return "application up on port: " + port;
}
}
USER-APP microservice:
I have added below properties in application.properties.
CHAT-BOOK.ribbon.listOfServers=localhost:8081,localhost:8082,localhost:8083
CHAT-BOOK.ribbon.eureka.enabled=false
server.port=9090
UserAppApplication class:
@SpringBootApplication
@RibbonClient(name = "CHAT-BOOK", configuration = RibbonConfiguration.class)
public class UserAppApplication {
@Bean
@LoadBalanced
public RestTemplate getTemplate() {
return new RestTemplate();
}
public static void main(String[] args) {
SpringApplication.run(UserAppApplication.class, args);
}
}
RibbonConfiguration.java
public class RibbonConfiguration {
@Autowired
IClientConfig ribbonClient;
@Bean
public IPing ping(IClientConfig ribbonClient) {
return new PingUrl();
}
@Bean
public IRule rule(IClientConfig ribbonClient) {
return new AvailabilityFilteringRule();
}
}
UserContoller.java
@RestController
public class UserContoller {
@Autowired
private RestTemplate template;
@GetMapping("/invoke")
public String invokeChatbook() {
String url = "http://CHAT-BOOK/chatbook/chatnow";
return template.getForObject(url, String.class);
}
}
参考网址:
https://www.youtube.com/watch?v=ueyVjOnDHYQ
当我运行上面的应用程序时,我会得到下面的错误。
2020-04-14 11:27:50.013 WARN 9996 --- [nio-9090-exec-5] com.netflix.loadbalancer.RoundRobinRule : No up servers available from load balancer: DynamicServerListLoadBalancer:{NFLoadBalancer:name=CHAT-BOOK,current list of Servers=[localhost:8081, localhost:8082, localhost:8083],Load balancer stats=Zone stats: {unknown=[Zone:unknown; Instance count:3; Active connections count: 0; Circuit breaker tripped count: 0; Active connections per server: 0.0;]
},Server stats: [[Server:localhost:8081; Zone:UNKNOWN; Total Requests:0; Successive connection failure:0; Total blackout seconds:0; Last connection made:Thu Jan 01 05:30:00 IST 1970; First connection made: Thu Jan 01 05:30:00 IST 1970; Active Connections:0; total failure count in last (1000) msecs:0; average resp time:0.0; 90 percentile resp time:0.0; 95 percentile resp time:0.0; min resp time:0.0; max resp time:0.0; stddev resp time:0.0]
, [Server:localhost:8082; Zone:UNKNOWN; Total Requests:0; Successive connection failure:0; Total blackout seconds:0; Last connection made:Thu Jan 01 05:30:00 IST 1970; First connection made: Thu Jan 01 05:30:00 IST 1970; Active Connections:0; total failure count in last (1000) msecs:0; average resp time:0.0; 90 percentile resp time:0.0; 95 percentile resp time:0.0; min resp time:0.0; max resp time:0.0; stddev resp time:0.0]
, [Server:localhost:8083; Zone:UNKNOWN; Total Requests:0; Successive connection failure:0; Total blackout seconds:0; Last connection made:Thu Jan 01 05:30:00 IST 1970; First connection made: Thu Jan 01 05:30:00 IST 1970; Active Connections:0; total failure count in last (1000) msecs:0; average resp time:0.0; 90 percentile resp time:0.0; 95 percentile resp time:0.0; min resp time:0.0; max resp time:0.0; stddev resp time:0.0]
]}ServerList:com.netflix.loadbalancer.ConfigurationBasedServerList@387e7238
2020-04-14 11:27:50.016 WARN 9996 --- [nio-9090-exec-5] c.netflix.loadbalancer.BaseLoadBalancer : LoadBalancer [CHAT-BOOK]: Error choosing server for key default
我运行三台服务器(8081,8082,8083)。但是它显示负载平衡器中没有可用的服务器。
错误1:
java.lang.NullPointerException: null
at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:890) ~[guava-28.2-android.jar:na]
at com.google.common.cache.LocalCache.get(LocalCache.java:3848) ~[guava-28.2-android.jar:na]
at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3873) ~[guava-28.2-android.jar:na]
at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4798) ~[guava-28.2-android.jar:na]
at com.netflix.loadbalancer.LoadBalancerStats.getServerStats(LoadBalancerStats.java:185) ~[ribbon-loadbalancer-2.3.0.jar:2.3.0]
at com.netflix.loadbalancer.LoadBalancerStats.getSingleServerStat(LoadBalancerStats.java:372) ~[ribbon-loadbalancer-2.3.0.jar:2.3.0]
at com.netflix.loadbalancer.AvailabilityPredicate.apply(AvailabilityPredicate.java:73) ~[ribbon-loadbalancer-2.3.0.jar:2.3.0]
at com.netflix.loadbalancer.AvailabilityPredicate.apply(AvailabilityPredicate.java:35) ~[ribbon-loadbalancer-2.3.0.jar:2.3.0]
at com.netflix.loadbalancer.CompositePredicate.apply(CompositePredicate.java:52) ~[ribbon-loadbalancer-2.3.0.jar:2.3.0]
at com.netflix.loadbalancer.CompositePredicate.apply(CompositePredicate.java:40) ~[ribbon-loadbalancer-2.3.0.jar:2.3.0]
at com.netflix.loadbalancer.AvailabilityFilteringRule.choose(AvailabilityFilteringRule.java:86) ~[ribbon-loadbalancer-2.3.0.jar:2.3.0]
at com.netflix.loadbalancer.BaseLoadBalancer.chooseServer(BaseLoadBalancer.java:755) ~[ribbon-loadbalancer-2.3.0.jar:2.3.0]
at com.netflix.loadbalancer.ZoneAwareLoadBalancer.chooseServer(ZoneAwareLoadBalancer.java:113) [ribbon-loadbalancer-2.3.0.jar:2.3.0]
at org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.getServer(RibbonLoadBalancerClient.java:189) [spring-cloud-netflix-ribbon-2.2.2.RELEASE.jar:2.2.2.RELEASE]....
错误 2:
java.lang.IllegalStateException: No instances available for CHAT-BOOK
at org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.execute(RibbonLoadBalancerClient.java:119) ~[spring-cloud-netflix-ribbon-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.execute(RibbonLoadBalancerClient.java:99) ~[spring-cloud-netflix-ribbon-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.cloud.client.loadbalancer.LoadBalancerInterceptor.intercept(LoadBalancerInterceptor.java:58) ~[spring-cloud-commons-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:93) ~[spring-web-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.http.client.InterceptingClientHttpRequest.executeInternal(InterceptingClientHttpRequest.java:77) ~[spring-web-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48) ~[spring-web-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53) ~[spring-web-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:739) ~[spring-web-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:674) ~[spring-web-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:315) ~[spring-web-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at com.loadbalanced.api.UserContoller.invokeChatbook(UserContoller.java:17) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_231]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_231]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_231]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_231]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190) ~[spring-web-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) ~[spring-web-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105) ~[spring-webmvc-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:879) ~[spring-webmvc-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793) ~[spring-webmvc-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040) ~[spring-webmvc-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) ~[spring-webmvc-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) ~[spring-webmvc-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:634) ~[tomcat-embed-core-9.0.33.jar:9.0.33].....
谁能建议我如何解决上述问题。
先谢谢了
看起来服务没有通过eureka解决。请检查这些是否在eureka中注册,并检查eureka是否未被以下属性禁用
CHAT-BOOK.ribbon.eureka.enabled=false
如果您不使用eureka,请设置以下属性
CHAT-BOOK.ribbon.eureka.enabled=false
CHAT-BOOK.ribbon.NIWSServerListClassName=com.netflix.loadbalancer.ConfigurationBasedServerList
CHAT-BOOK.ribbon.listOfServers=http://localhost:9999/
尝试删除@LoadBalanced批注以修复Error2。
带Spring Cloud和Eureka的功能区:java.lang.IllegalStateExc的:没有可用于Samarths-MacBook-Pro.local的实例
带有Spring Cloud和Eureka Java . lang . illegalstateexception的功能区:本地主机没有可用的实例
https://tech.asimio.net/2016/11/14/Microservices-Registration-and-Discovery-using-Spring-Cloud-Eureka-Ribbon-and-Feign.html#load-balancing-requests-using-resttemplate-and-loadbalanced
由于您已将策略指定为 PingUrl,因此您需要在服务中添加“/”的@RequestMapping,以便功能区可以 ping 以了解实例的可用性:
@RequestMapping(value = "/")
public String home() {
return "home";
}
我更倾向于第一种方法,但想确认其他人对这种情况的看法。
嗨,我创建了两个微服务。spotparkin和2。spotparking2和他们已经成功注册到eureka服务器,然后我创建了ribbon客户端,并尝试使用应用程序名SpotParking进行rest调用,这是我在两个微服务的application.yml文件中给出的应用程序名,但我得到以下错误: 2016-10-16 13:28:35.177错误11304---[nio-7213-exec-1]
我一直在尝试使用Zuul和Eureka连接微服务,除了通过基于ServiceID的Zuul重新路由之外,大部分都成功了。我拥有的是Spring Boot Zuul和Eureka应用程序,以及一个在Eureka注册的基于节点的微服务。Zuul和微服务都在Eureka注册,并显示在Eureka控制面板上,但是,当我试图通过Zuul路由到微服务时,我会遇到以下异常: 通过IP路由似乎有效,但我不需要它。
本文向大家介绍PHP基于socket实现客户端和服务端通讯功能,包括了PHP基于socket实现客户端和服务端通讯功能的使用技巧和注意事项,需要的朋友参考一下 本文主要介绍了PHP基于socket实现的简单客户端和服务端通讯功能,可实现服务端接收客户端发送的字符串进行翻转操作后返回客户端的功能,需要的朋友可以参考下 服务端: 客户端: 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多
Lazy 微服务客户端 Sometimes you have to load initial data before you can create your @Client(). In this case, you can use ClientProxyFactory, which provides create() method. 有时候在创建@Client()之前你需要加载原始数据。这时,你可
我有一个包含10个微服务的微服务架构,每个微服务提供一个客户端。在由微服务团队管理/控制的客户机内部,我们只接收参数并将它们传递给一个通用http调用程序,该调用程序接收endpoint和N个params,然后进行调用。所有微服务都使用http和web api(我猜技术并不重要)。 对于我来说,作为微服务团队提供一个客户是没有意义的,应该是消费者的责任,如果他们想创建一些抽象或者直接调用它是他们的