Spring Boot Zuul : Map Multiple Route URLs - spring-boot

We are using Spring Boot with Zuul Proxy to forward the API requests to APIs. Sample Configuration is as below:
zuul.routes.common.url=http://10.0.0.1:8081/common
zuul.routes.meta.url=http://10.0.0.2:8082/meta
Every thing works fine with this. For balancing our load and utilising underlying servers effeciently, we would like to specify multiple URLs as part of the configuration and enable request forwarding for one of the URL. To be precise, we would like to configure the proxy config as given below by providing comma delimited list of endpoints which can handle the requests.
zuul.routes.common.url=http://10.0.0.1:8081/common,http://10.0.0.11:8081/common
zuul.routes.meta.url=http://10.0.0.2:8082/meta,http://10.0.0.12:8082/meta
But unfortunately, such config is resulting in "Resource not found Error".
Questions:
Is this a possible configuration?
if not, Is it possible to achieve this by any other means?
Regards,
Manjunath
Edit : Answer
Its not possible to configure multiple URLs just with Zuul. Request need to be load balanced using Ribbon. Here is the sample configuration with ribbon:
zuul.routes.common.path=/**
zuul.routes.common.serviceId=common
common.ribbon.listOfServers=http://10.0.0.1:8081/common,http://10.0.0.2:8081/common

You want to use Ribbon, and the property client.ribbon.listOfServers. Here is a quick example
zuul:
routes:
users:
path: /myusers/**
serviceId: users
ribbon:
eureka:
enabled: false
users:
ribbon:
listOfServers: example.com,google.com

Related

Specifying route URI in Spring Cloud Gateway Configuration

Here is the yml for spring cloud gateway. I want to write URI without load balancing. But as I'm using Eureka, I don't think hardcoding something like "localhost:6678" is a good idea. I would like to specify the service name, without the lb prefix. Any way to write it ?
spring:
cloud:
gateway:
routes:
- id: before_route
uri: lb://hello-service
I'm seeing this on the console when I run the gateway:
You already have RibbonLoadBalancerClient on your classpath. It will be used by default. As Spring Cloud Ribbon is in maintenance mode. We recommend switching to BlockingLoadBalancerClient instead. In order to use it, set the value of `spring.cloud.loadbalancer.ribbon.enabled` to `false` or remove spring-cloud-starter-netflix-ribbon from your project.
What is the official alternative of Ribbon? How can I enable it in my project instead of Ribbon?
Edit: I'm trying to avoid load balancing for now because of poor performance. Without lb I'm getting my request served within 150ms whereas lb makes it 500ms+
Thanks in advance!

Zuul routing in microservices

I am trying to access a microservice endpoint through a gateway using jhipster. The end point is from a legacy system and starts with "/d" and cannot be modified. I want the gateway to route all the requests that start with '/d/** ' to my microservice where I have a rest controller that will handle the requests that is mapped to '/api/d/**'
I'm trying to work using the documentation, so I have in my gateway the route:
zuul:
routes:
my-service-route:
path:/d/**
serviceId: serviceName
I saw that using url in zuul configuration you can specify the url directly, but I use jhipster registry so I can't approach the problem like that. As far as I understand I have to write a custom Zuul Filter or a Zuul Route Configuration that will route the requests to my service.
So I have 2 problems:
I can't access the gateway if I use a rest that begins with /d
I can't route the requests to my microservice in the way that I expect:
/d/service to be routed to my microservice where I have a restcontroller with a mapping to "/d/service".
Any info on how I should approach this is highly appreciated.
Thanks.
EDIT:
I already added my path in WebConfig source.registerCorsConfiguration("/d/**", config); and in SecurityConfiguration .antMatchers("/d/**").authenticated()
Can you try this below configuration in application.properties also you can change it to yml accordingly. so any request coming as /d/* will redirect to serviceName application instance.
zuul.routes.serviceName.serviceId=serviceName
zuul.routes.serviceName.path=/d/**
zuul.routes.serviceName.sensitive-headers=Set-Cookie,Authorization
hystrix.command.serviceName.execution.isolation.thread.timeoutInMilliseconds=600000

How to register non Spring Boot MicroService in Eureka discovery server

I have recently installed a micro service infrastraucture based on Spring Boot + Spring Cloud.
My Spring Boot microservices register in my Eureka server and Zuul automaticaly redirects requests to them.
I have a Drupal content manager that exposes content through REST interface and I'd like it to take part in the discovery rave party. How can I have my drupal register it self in the Eureka server so Zuul redirects the corresponding calls to it?
As an ugly workaround I wonder if I can have automatic discovery and routing running in Zuul while manually configuring some REST paths to be redirected to the drupal server? (Using zuul.routes... property files)
I found that I can add manual zuul routes in bootstrap.yaml
I have tried adding it in the application yaml property files in configuration server but for some reason they are ignored when the Eureka discovery server is working.
Anyway, bootstrap.yaml works. Example:
zuul:
routes:
mta_api:
path: /mta_api/**
url: http://my-non-springboot-rest-service.com/
stripPrefix: false
You could add sidecar to your non-springboot application. This would allow Eureka support.
Source: Dead- http://cloud.spring.io/spring-cloud-static/Edgware.SR4/single/spring-cloud.html#_polyglot_support_with_sidecar
Current: https://cloud.spring.io/spring-cloud-static/Dalston.SR5/multi/multi__polyglot_support_with_sidecar.html

Spring Cloud Gateway in CloudFoundry

I've been trying to get my apps to run after deploing them to a CloudFoundry instance. The instance I'm using will not allow to perform requests using http (they will simply timeout) so I have to route all requests to https.
The components/versions I am using are:
Java 10
Spring Boot 2.0.4.RELEASE/Spring Cloud Finchley.SR1
spring-cloud-gateway
spring-cloud-config-server
spring-cloud-starter-netflix-eureka
The failing config
EurekaClient Config (in gateway and the backend where the gw should route to)
eureka:
client:
serviceUrl:
defaultZone: ${DISCOVERY_SERVICE_URL:http://localhost:8061}/eureka/
instance:
hostname: ${vcap.application.uris[0]:localhost}
nonSecurePortEnabled: false
securePortEnabled: true
securePort: ${server.port}
statusPageUrl: https://${eureka.instance.hostname}/actuator/info
healthCheckUrl: https://${eureka.instance.hostname}/actuator/health
homePageUrl: https://${eureka.instance.hostname}/
secure-virtual-host-name: https://${vcap.application.application_uris[0]}
Gateway Config
spring:
cloud:
gateway:
discovery:
locator:
enabled: true
routes:
- id: user-service
uri: lb://user-service
predicates:
- Path=/user/**
filters:
- RewritePath=/user/(?<segment>.*), /$\{segment}
Things I have already tried:
Using lb:https://user-service like described in docs -> Will have no effect as far as I can see
Use real urls to the apps (uri: https://user-service.cf-instance.io) -> Routing works as expected.
But I do not want to define the urls in my config, they should returned by eureka and build up correctly by the gateway.
Thanks in advance
Edit:
Here is the output of /eureka/apps
https://pastebin.com/WP3b6PQG
I am currently working to get the current code into GitHub I will edit this post when I've found the time to get a clear state.
Edit 2:
You can find the full example (With SpringCloudGateway, Eureka, ...) at my GitHub
This is an running example, the applied config will not use the Eureka. To use Eureka the gateway-service-cloud.yml in config service has to be adopted.
- id: user-service
uri: lb://user-service
Please ignore the documentation service, this will not work yet, I first need to rewrite the path.
Ok, I found out the solution during fixing the "routing" problem with my documentation-service.
My problem was setting the property eureka.instance.securePort to ${server.port}. This property has to be set to 443 (the default 443 is not applied when nothing is set). When adding this to my configurations everything works as expected after pushing my application.

Routing request to same service registered as two different service-ID

In my spring boot application, I m using Eureka server for the discovery service.
In one of my Discovery client application I am using zuul proxy to route the requests to different services registered with the Discovery Server.
I have one resource application which is responsible for storing the data into the db. I have created two instances for this service registered as two different service with the discovery service.
The api published for this service lets say is /resources Get,Post, etc
The client application sends request like /definitions and /locations for the two instances of this resource service.
Now my problem is I want to map this /definitions to service-id 1/resources and locations to /service-id2/resources.
I m not sure how to do this as when I send /defnitions from the client application it expects /definitions to be there in the resource application which is not the case.
I am trying something like this
zuul:
routes:
locations:
path: /locations/**
rewrite: /resources/**
serviceId: location_service
stripPrefix: false
definitions:
path: /definitions/**
rewrite: /resources/**
serviceId: definition_service
stripPrefix: false
you are using stripPrefix: false in both cases. It means zuul will not cut it from request url and pass to your proxied service. Try to play with that.
At least in spring-cloud org.springframework.cloud.netflix.zuul.filters.ZuulProperties file there is no 'rewrite' property, are you sure its correct?

Resources