Spring Cloud Sidecar configuration issue

Viewed 368

I have a very simple sidecar application - just the required annotations and the main method, like this:

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

I also have a service sitting behind it, on the same host, which has a GET /joke endpoint.

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.

Now, If I add this to the sidecar configuration:

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

then calling GET http://localhost:5678/joker/joke works as expected.

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.

2 Answers

I think you need more notations like these in 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

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

note this configuration was useful for spring-boot 1.5.6.RELEASE

If you are using Eureka yes, the routing is transparent. The sidecar app registers itself with Eureka BUT sets homePageUrl value of Eureka InstanceInfo object to the actual host and port of your microservice. And this is the value your clients will use to make calls to your microservice.

Related