简体   繁体   English

Spring Cloud Sidecar 配置问题

[英]Spring Cloud Sidecar configuration issue

I have a very simple sidecar application - just the required annotations and the main method, like this:我有一个非常简单的 sidecar 应用程序 - 只是所需的注释和主要方法,如下所示:

@SpringBootApplication
@EnableSidecar
public class SidecarApplication {
    ...
}

I also have a service sitting behind it, on the same host, which has a GET /joke endpoint.我还有一个服务在它后面,在同一台主机上,它有一个 GET /joke 端点。

The sidecar configuration:边车配置:

server.port=5678
spring.application.name=joker

sidecar.port=8083
sidecar.home-page-uri=http://localhost:8083/
sidecar.health-uri=http://localhost:8083/health.json

management.security.enabled=false
logging.level.root=DEBUG

However, when calling GET http://localhost:5678/joke , I get 404. If I call GET http://localhost:8083/joke , I do get a valid response.但是,当调用 GET http://localhost:5678/joke 时,我得到 404。如果我调用 GET http://localhost:8083/joke ,我会得到一个有效的响应。

Now, If I add this to the sidecar configuration:现在,如果我将其添加到 sidecar 配置中:

zuul.routes.joker.url=http://localhost:8083/

then calling GET http://localhost:5678/joker/joke works as expected.然后调用 GET http://localhost:5678/joker/joke按预期工作。

Am I missing something, or is this expected behavior?我错过了什么,还是这是预期的行为? I would have expected no additional configuration to be necessary for the sidecar to route all incoming requests to the wrapped service, and I'd want the url to be used for accessing the service behind the sidecar not to need to contain a service name.我希望 sidecar 不需要额外的配置来将所有传入请求路由到包装的服务,并且我希望 url 用于访问 sidecar 后面的服务而不需要包含服务名称。

I think you need more notations like these in application.properties:我认为在 application.properties 中你需要更多这样的符号:

spring.application.name = joke
server.port = 5678

eureka.client.serviceUrl.defaultZone = http: // localhost: 9000 / eureka
eureka.client.register-with-eureka = true
eureka.client.fetch-registry = true

sidecar.port = 8083
sidecar.health-uri = http: // localhost: 8083 / health

management.security.enabled = false

/ * example * /
zuul.routes.wstore.path = / wstore / **
zuul.routes.wstore.url = http: // localhost: 8083

In the application should have these 3 notations在应用程序中应该有这3个符号

@SpringBootApplication
@EnableSidecar
@EnableDiscoveryClient
public class SidecarApplication {...}

note this configuration was useful for spring-boot 1.5.6.RELEASE注意这个配置对 spring-boot 1.5.6.RELEASE 很有用

If you are using Eureka yes, the routing is transparent.如果您使用的是Eureka ,则路由是透明的。 The sidecar app registers itself with Eureka BUT sets homePageUrl value of Eureka InstanceInfo object to the actual host and port of your microservice. sidecar应用程序向Eureka注册自己,但将 Eureka InstanceInfo对象的homePageUrl值设置为微服务的实际主机和端口。 And this is the value your clients will use to make calls to your microservice.这就是您的客户将用于调用您的微服务的价值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM