This question is about zuul and routing. Now to get zuul routing is quite easy in your application.yml you have the following
routes:
silver:
path: "/silver/**"
serviceId: "SILVER-MICO-SERVICE"
stripPrefix: true
gold:
path: "/gold/**"
serviceId: "GOLD-MICO-SERVICE"
stripPrefix: false
So if your URL has silver in it, it will direct the silver micro service, if it has gold it directs to the gold micro service.
But I have a 3rd service, that I want to call before I direct the to the silver or gold. so i want something like
routes:
silver:
path: "/silver/**"
serviceId: "SILVER-MICO-SERVICE"
stripPrefix: true
gold:
path: "/gold/**"
serviceId: "GOLD-MICO-SERVICE"
stripPrefix: false
throttle
path: "/throttle/**"
serviceId: "THROTTLE-MICO-SERVICE"
stripPrefix: false
And when say silver is called
I will have the following in my filter, I would have a throttleFilter which will call out to the throttle micro service. But I have no idea how to code a zuul call in Java.
Thanks for any help
Ok this is the code to do what I want to do. The functionality I needed was supplied by the EurekaClient
zuul
throttling:
path: "/throttling/**"
serviceId: "SITE-THROTTLING"
stripPrefix: false
And in the code I have
@Autowired
private EurekaClient eurekaClient;
private boolean checkThrottling(String url) {
InstanceInfo service = eurekaClient
.getApplication("SITE-THROTTLING")
.getInstances()
.get(0);
StringBuilder sb = new StringBuilder(service.getHomePageUrl())
.append("/throttling")
.append("?paramUrl=")
.append(url);
return webSevice.sendPost(sb.toString());
public boolean sendPost(String url) {
WebClient webClient = WebClient.create();
Boolean flag = webClient.get()
.uri(url)
.retrieve()
.bodyToMono(Boolean.class)
.block();
return flag;