Spring Cloud Zuul-Gateway mapping with Config-Server - spring-boot

I'm developing a spring-microservice architecture with following modules (see the architecture diagram below):
Configuration-server
Eureka-Server
Zuul Api Gateway
User-api(Config-Server-Client, Eureka-Client)
Stats-api(Config-Server-Client, Eureka-Client)
Auth-Service (in-progress/out of context)
It's is more of a configuration approach rather than a bug. So far everything is running fine.
For most of the configurations of core-apis, I'm loading them from config-Server.
What should be the actual or recommended way if we use config-server with Api-Gateway?
Would it be good to map(load from) the configuration of Zuul-Gateway to my Config-Server as with other core apis like User-Api and Stats-Api.
And if I did so what should be the order of starting the applications?
Like:
1. Start the Config-Server
2. Eureka Server
3. Zuul Gateway
4. Core-Apis
Thanks :)

I have build a similar architecture for testing purpose. You can find in the link below:
https://github.com/rshtishi/payroll
The order I use to start the services is like below:
Configuration Server (Spring Cloud Config Server) is always the first start. Here are the configuration for all the services.
Eureka Server, is responsible for registering all services.
After starting the service above, you can start whatever you wish api-services or zuul gateway server. Zuul gateway server will access the api services through eureka. So it doesn't matter the order.

Related

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

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.

Microservices Config and eureka service which one to start first?

I am creating a simple project in microservices using spring boot and netflix OSS to get my hands dirty. I have created two services
config service which has to register itself in discovery(eureka)
service.
discovery service which requires config service to be running to get its configuration.
Now when I am starting these services, both services fails due to inter dependency. What are the best practices resolve this issue and which one to start first.
PS:- I know I am creating circular dependency, But what is the way to deal with situation like this where I want to keep eureka configuration also with the config server
Thanks
I believe that you can find the answer for your question in the official spring cloud config server documentation:
Here: http://cloud.spring.io/spring-cloud-config/spring-cloud-config.html#_spring_cloud_config_client
Basically you have to choose between a "Config First Bootstrap" or "Discovery First Bootstrap".
From the docs:
"If you are using a `DiscoveryClient implementation, such as Spring Cloud Netflix and Eureka Service Discovery or Spring Cloud Consul (Spring Cloud Zookeeper does not support this yet), then you can have the Config Server register with the Discovery Service if you want to, but in the default "Config First" mode, clients won’t be able to take advantage of the registration.
If you prefer to use DiscoveryClient to locate the Config Server, you can do that by setting spring.cloud.config.discovery.enabled=true (default "false"). The net result of that is that client apps all need a bootstrap.yml (or an environment variable) with the appropriate discovery configuration. (...)"

Load Balancing micro services using Spring cloud Netflix OSS

I have a microservice built using Spring Boot and Netflix OSS. I have used Central config server, Eureka and Zuul. Because of scalability multiple instances of the services is running on different port. All the instances are registered in Eureka but requests are going to only last registered server.
How to load balance services. Should I use ribbon in Zuul to load balance? Please let me know how to achieve load balancing on same service running on multiple instances.
If there is a code change required a snippet then please post a code snippet as well.
Application Config
spring.application.name=book-service
server.port=0
eureka.client.region = default
eureka.client.registryFetchIntervalSeconds = 5
eureka.client.serviceUrl.defaultZone=http://discUser:discPassword#localhost:10082/eureka/
#eureka.instance.metadataMap.instanceId=${spring.application.name}:${spring.application.instance_id:${random.value}}
eureka.instance.instanceId=${spring.application.name}:${spring.application.instance_id:${random.value}}
eureka.instance.leaseRenewalIntervalInSeconds=5
eureka.instance.leaseExpirationDurationInSeconds=5
Eureka Config
spring.application.name=discovery
server.port=10082
eureka.instance.hostname=localhost
eureka.client.serviceUrl.defaultZone=http://discUser:discPassword#localhost:10082/eureka/
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
spring.session.store-type=hash-map
ZUUL Config
spring.application.name=gateway
server.port=10080
eureka.client.region = default
eureka.client.registryFetchIntervalSeconds = 5
management.security.sessions=always
zuul.routes.book-service.path=/book-service/**
zuul.routes.book-service.sensitive-headers=Set-Cookie,Authorization
hystrix.command.book-service.execution.isolation.thread.timeoutInMilliseconds=600000
#zuul.routes.rating-service.path=/rating-service/**
#zuul.routes.rating-service.sensitive-headers=Set-Cookie,Authorization
#hystrix.command.rating-service.execution.isolation.thread.timeoutInMilliseconds=600000
zuul.routes.discovery.path=/discovery/**
zuul.routes.discovery.sensitive-headers=Set-Cookie,Authorization
zuul.routes.discovery.url=http://localhost:8082
hystrix.command.discovery.execution.isolation.thread.timeoutInMilliseconds=600000
logging.level.org.springframework.web.=debug
logging.level.org.springframework.security=debug
logging.level.org.springframework.cloud.netflix.zuul=debug
spring.session.store-type=hash-map
Registering application properly with Eureka will do the trick.
Below entries will uniquely register services with Eureka.
#eureka.instance.metadataMap.instanceId=${spring.application.name}:${spring.application.instance_id:${random.value}}
eureka.instance.instanceId=${spring.application.name}:${spring.application.instance_id:${random.value}}

Creating a Client/Service in Netflix Eureka

With regards to the Netflix Eureka Service Registry, I have setup the Eureka Netflix Server using Tomcat 8.0.35 successfully. I have also got the basic Example Service & Client to communicate with each other. I'm still new to Eureka and the management decision is to use Eureka with Spring as several new applications are written around the Spring framework.
I have been following the wiki in order to understand how the communication works (But with little to no success with registering services).. Eureka Github Wiki.
My question is: Do I need to create my own Eureka Service & Client in order to maintain a registry of about 50 cloud instances? (If so, can you please point me in the right direction).
I have hands on experience with Consul/RESTfull API, and have implemented Consul in production (using php, and qbit); however the Netflix Eureka Registry look's as though I need to learn eureka/spring + client/server java programming? I'm still getting used to the following terms.
Eureka Server (I successfully got this working using Tomcat8/JDK1.8 + the eureka.war)
Eureka Service (Some kind of stand-alone RESTfull service that queries the Eureka-Server and listens for client requests)
Eureka Client (Java snippet to be embedded into the Java servlets/jsp)?
Zuul (A type of routing/load-balancing app - similar to HaProxy ?)
Ribbon (A type of routing/load-balancing app - similar to HaProxy ?)
I would like to get the Service & Client configured for mostly non-AWS cloud instances. The Eureka Wiki is not very helpful when it comes to creating a working eureka service & client. Any help to point me in the right direction to implement a Eureka based RESTfull system would be helpful.
I suggest you to read this documentation about spring-cloud : http://cloud.spring.io/spring-cloud-static/spring-cloud.html
It should be a good start to setup a few simple spring-boot/spring-cloud services and start to use advanced tools like zuul/ribbon/hystrix ...
There is a simple example of distributed system using Spring Boot and Spring Cloud Netflix.
This project contains the following microservices:
requestor and responder which communicates via REST/HTTP
gateway microservice - Spring Boot app + Zuul
discovery microservice - Spring Boot app + Eureka
Moreover, requestor microservice uses Hystrix library.
As you can see, Spring Cloud provides a really good wrapper for Netflix solutions. As a result, you can start quickly with minimal configuration.

Resources