通过Eureka Server将server.contextPath设置为vs.hystrix.stream的URL的Spring Boot [英] Spring Boot with server.contextPath set vs. URL to hystrix.stream via Eureka Server

查看:316
本文介绍了通过Eureka Server将server.contextPath设置为vs.hystrix.stream的URL的Spring Boot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有正在运行Turbine实例的Eureka Server,并且有一些与其连接的发现客户端.一切正常,但是如果我注册设置了server.contextPath的发现客户端,则InstanceMonitor无法识别该客户端,并且Turbine流无法合并其hystrix.stream.

I have Eureka Server with Turbine instance running and a few discovery clients that are connected to it. Everything works fine, but if I register a discovery client that has server.contextPath set, it didn't get recognized by InstanceMonitor and Turbine stream is not able to combine its hystrix.stream.

这是在Eureka/Turbine服务器日志中的外观:

This is how it looks in the logs of Eureka/Turbine server:

2015-02-12 06:56:23.265  INFO 1 --- [        Timer-0] c.n.t.discovery.InstanceObservable       : Hosts up:3, hosts down: 0
2015-02-12 06:56:23.266  INFO 1 --- [        Timer-0] c.n.t.monitor.instance.InstanceMonitor   : Url for host: http://user-service:8887/hystrix.stream default
2015-02-12 06:56:23.268 ERROR 1 --- [InstanceMonitor] c.n.t.monitor.instance.InstanceMonitor   : Could not initiate connection to host, giving up: []
2015-02-12 06:56:23.269  WARN 1 --- [InstanceMonitor] c.n.t.monitor.instance.InstanceMonitor   : Stopping InstanceMonitor for: user-service default

com.netflix.turbine.monitor.instance.InstanceMonitor$MisconfiguredHostException: []
    at com.netflix.turbine.monitor.instance.InstanceMonitor.init(InstanceMonitor.java:318)
    at com.netflix.turbine.monitor.instance.InstanceMonitor.access$100(InstanceMonitor.java:103)
    at com.netflix.turbine.monitor.instance.InstanceMonitor$2.call(InstanceMonitor.java:235)
    at com.netflix.turbine.monitor.instance.InstanceMonitor$2.call(InstanceMonitor.java:229)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

它尝试从http://user-service:8887/hystrix.stream获取hystrix流,其中正确的URL(包括sever.contextPath应该为http://user-service:8887/uaa/hystrix.stream

It tries to get hystrix stream from http://user-service:8887/hystrix.stream where the correct URL including sever.contextPath should be http://user-service:8887/uaa/hystrix.stream

该客户端的application.yml包含:

server:
  port: 8887
  contextPath: /uaa

security:
  ignored: /css/**,/js/**,/favicon.ico,/webjars/**
  basic:
    enabled: false

我的问题是:我是否应该向此用户服务发现客户端添加一些其他配置选项,以注册正确的hystrix.stream URL位置?

My question is: should I add some additional configuration options to this user-service discovery client to register proper hystrix.stream URL location?

我还没有对此进行深入研究,如果能找到答案,我会告诉您.

I didn't dig into that yet, I will let you know if found something before getting answer to that question.

使用server.contextPathmanagement.context-path时存在一个问题.两者都设置后,涡轮流将在${HOST_URL}/${server.contextPath}/${management.context-path}/hystrix.stream上提供.在那种情况下,我必须使用server.contextPath删除(我在控制器@RequestMapping中将其替换为前缀).

There is one problem when it comes to using server.contextPath and management.context-path. When both are set, turbine stream is being served on ${HOST_URL}/${server.contextPath}/${management.context-path}/hystrix.stream. In that case I had to drop using server.contextPath (I replaced it with a prefix in controllers @RequestMapping).

现在,当您使用management.context-path时,将通过使用hystrix.stream作为前缀提供U​​RL的服务.在这种情况下,您必须遵循Spencer的建议并设置

Now, when you user management.context-path, then your hystrix.stream is being served from the URL that uses it as a prefix. In that case you have to follow Spencer's suggestion and set

turbine.instanceUrlSuffix=/{PUT_YOUR_MANAGEMENT_CONTEXT_PATH_HERE}/hystrix.stream

当然,必须为所有Discovery Client将此management.context-path设置为相同的值-使用Spring Cloud Config

And of course this management.context-path must be set with the same value for all your Discovery Clients - it can be done easily with Spring Cloud Config http://cloud.spring.io/spring-cloud-config/spring-cloud-config.html

推荐答案

您可以设置turbine.instanceUrlSuffix.<CLUSTERNAME>=/uaa/hystrix.stream.其中<CLUSTERNAME>是在turbine.aggregator.clusterConfig中设置的值. Turbine 1 Wiki 的所有配置选项均有效.您无需在后缀中添加端口,因为Spring Cloud Netflix Turbine从eureka添加了端口.

You can set turbine.instanceUrlSuffix.<CLUSTERNAME>=/uaa/hystrix.stream. Where <CLUSTERNAME> is the value set in turbine.aggregator.clusterConfig. All of the config options from the Turbine 1 wiki work. You don't need to add the port to the suffix as Spring Cloud Netflix Turbine adds the port from eureka.

这篇关于通过Eureka Server将server.contextPath设置为vs.hystrix.stream的URL的Spring Boot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆