Specifying route URI in Spring Cloud Gateway Configuration - spring

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!

Related

How to detect new REST calls dynamically as and when they are available?

I am creating an API gateway using Netflix Zuul and Netflix Eureka doing the part of service registration for service discovery for a microservices framework.
I am trying to support a use case where new micro-services may come up which expose REST calls, or existing micro-services may get upgraded to expose new REST calls with version as part of their URL etc. Eureka runs as a dedicated springboot application and Zuul runs as a dedicated application. The application.prop or application.yml file of Zuul is where i am putting config for zuul.routes for each micro-services
My zuul's application.yml looks something like this to support one microservice config.
zuul:
routes:
example:
path: /example/**
stripPrefix: false
serviceId: zuul-service
If i bring down zuul add another such snippet of config under zuul:routes:
and then bring up zuul again, i will start seeing the new endpoint. But i want that to happen dynamically. Like Eureka will dynamically detect any new micro-services that come up or go down. If zuul can get in sync with Eureka then all my rest endpoints can be exposed perfectly through my Zuul api gateway.
Any suggestions on what i may be missing or add any other open source third party to achieve this will be helpful.

Spring Boot Zuul : Map Multiple Route URLs

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

Zuul proxy that discovers routes dynamically

I have a simple Zuul app that has a single route in the application.yml to route to my microservice. It's working.
However, what I'm looking for is a more dynamic solution where I can wire up routes dynamically, either through code or perhaps by POSTing to some Zuul endpoints during a build (possibly by using springfox and a swagger definition from microservices). I could not find an API for Zuul.
I'm somewhat aware of Eureka and that seems like a solution to abstract away the routing by doing discovery. However, I'm curious if there's a solution without introducing Eureka. If there's a way to wire up these routes in Zuul during a build vs. having to edit the application.yml every time.
Thanks in advance.
If you go for Eureka this will actually work ootb. Zuul as packaged in spring cloud will automatically expose every service using its name. So if you register a service called users in Eureka, Zuul will automatically create a route /users forwarding to the instances by default. That will only allow simple url structures but should solve your problem.
Please see the official documentation for details:
By convention, a service with the ID "users", will receive requests from the proxy located at /users (with the prefix stripped). The proxy uses Ribbon to locate an instance to forward to via discovery, and all requests are executed in a hystrix command, …
I'm actually editing a blog post about this exact topic (Routing and Filtering using Spring Cloud Zuul Server) but the source code has been available and working for some time now. Feel free to use it as a reference:
https://bitbucket.org/asimio/zuulserver
https://bitbucket.org/asimio/discoveryserver (in case routes are configured with serviceIds)
https://bitbucket.org/asimio/demo-config-properties/src (Zuul-Server-refreshable.yml where routes are dynamically updated).
Look at the refreshable Spring profile settings. This Zuul setup works with both, hard-coding routes url or discovered using Eureka.
It also acting as a Spring Cloud Config client so that routes could be dynamically updated via Git, which is also covered in another blog post: Refreshable Configuration using Spring Cloud Config Server, Spring Cloud Bus, RabbitMQ and Git.

Route Existing Services via ZUUL without adding routing rule

I am trying to route existing services via Spring cloud Netflix Zuul.
I have an existing service available at below url,
http://localhost:3080/query-service/getquery/1
Out of the box, with zuul I can route to the service as below,
localhost:9000/queryservice-id/queryservice/getquery/1, with "queryservice-id" as the service-id of the service when it is registered in Service Registry. The zuul port is 9000.
I do not want to change the context path and service path information when accessing the service via ZUUL.
With ZUUL, I want to access the service as below,
http://localhost:9000/query-service/getquery/1
I do want to prefix with the "serviceId". This is because I do not want to impact any existing clients of the service. Only the host and port changes, without serviceId.
I was able to accomplish it as below with ZUUL Configuration,
zuul:
routes:
query-service:
path: /query-service/**
serviceId: query-service
stripPrefix: false
With the above configuration, I am able to only use the zuul host and port, the other service specific information remains as before. Seems like stripPrefix is helping in routing without the serviceId.
But, I have a lot of services and will be adding more services too.
For every such service, I do not want to be adding a rule like that to ZUUL configuration which will mean rebuilding and recycling the ZUUL Service.
I feel there should be a simpler and better way to accomplish this, without a big effort, because the change I want to do is common to all services
Is there a way to making this change common for alll the services I want
to be routed via ZUUL.
Thanks,
As checked with the Spring Cloud Netflix team this is recommended approach.
https://github.com/spring-cloud/spring-cloud-netflix/issues/1549

Spring cloud config client without Eureka, Ribbon and spring boot

I have spring web application (not spring boot) running in AWS. I am trying to create centralized configuration server. How to refresh the spring-cloud-client after the changing the properties? As per tutorial
Actuator endpoint by sending an empty HTTP POST to the client’s refresh endpoint, http://localhost:8080/refresh, and then confirm it worked by reviewing the http://localhost:8080/message endpoint.
But my aws Ec2 instances are behind the loadbalancer so i can't invoke the client url. I didn't understand the netflix Eureka and Ribbon much but it seems like adding another level of load balancer in the client side. I don't like this approach. Just to change a property i don't want to make the existing project unnecessarily complex. Is there any other way? or Am I misunderstood Eureka/Ribbon usage?
I have looked at the spring-cloud-config-client-without-spring-boot, spring-cloud-config-client-without-auto-configuration none of them have answer. First thread was answered in 2015. Wondering is there any update?
To get the configuration properties from a config server. You can do a http request. Example:
From the documentation we can see:
/{application}/{profile}[/{label}]
/{application}-{profile}.yml <- example
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties
So if you would do a request to http://localhost:8080/applicationName-activeProfile.yml you would receive the properties in .yml format for the application with that name and active profile. Spring boot config clients would automatically provide these values but you will have to provide em manually.
You don't need Eureka/Ribbon for this to work, it's a separate component.
More info: http://cloud.spring.io/spring-cloud-static/spring-cloud.html#_spring_cloud_config
Maybe you could even use spring-cloud-config but I'm not sure what extra configuration is needed without spring-boot.
https://cloud.spring.io/spring-cloud-config/

Resources