Reputation: 1360
I'm using netflix zuul embedded in a spring boot 1.5.x application. Behind zuul are some microservices. These microservices expose public endpoints under /public/** .
Now i want to expose these public endpoints via zuul api gateway but stripping the "/public" out of the final api gateway url.
Example (expected) from outside (request through zuul api gateway):
api.yourdomain.tld/path/to/service/endpoint
Zuul should forward this request to (with /public in the url):
service:{port}/public/path/to/service/endpoint
How can i achieve this without using url parameter in the zuul configuration. I would like to rely on the internal client side load balancing using serviceId parameters. I couldn't figure it out.
If this isn't a good pattern, should i split my microservices into webservices and core-services? So that only webservices are mounted/accessible via Zuul?
This configuration works fine but it uses the url parameter instead of serviceId:
custom-service:
path: /path/to/service/endpoint/**
stripPrefix: false
url: http://custom-service:51022/public
sensitiveHeaders:
Upvotes: 2
Views: 4087
Reputation: 1056
You need service discovery via Spring Cloud Netflix Eureka , check Introduction and How to declare routes with serviceId
After setting that up, enable zuul proxy and discovery client in zuul application
@EnableZuulProxy
@EnableDiscoveryClient
@SpringBootApplication
public class ZuulProxyApplication {
public static void main(String[] args) {
SpringApplication.run(ZuulProxyApplication.class, args);
}
}
than:
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=true
Zuul application don't need to be registered with Eureka, and it should fetch the registry.
And than you can say:
zuul:
routes:
custom-service:
path: /path/to/service/endpoint/**
stripPrefix: false
serviceId: customServiceId
If you want to have defined multiple routes for one service, do:
zuul:
routes:
custom-service:
path: /path/to/service/endpoint/**
stripPrefix: false
serviceId: customServiceId
custom-service:
path: /second_path/to/service/endpoint/**
stripPrefix: false
serviceId: customServiceId
Upvotes: 3