migration from spring zuul to spring cloud - spring

we are migrating from spring zull to spring cloud. for zuul, we had simple routing configuration:
zuul:
host:
connection-request-timeout-millis: 60000
socket-timeout-millis: 60000
sensetiveheaders:
routes:
ui-service:
path: /**
url: "some url"
ignoredPatterns: /abc, /bcd/**
as per my understanding, ignoredpatterns means allowed paths. other pattern will not be allowed and will return back to the client. Please correct me if my understanding is wrong.
my next question is: how I can do similar configuration in spring cloud.
Any help will be appreciable. thanks in advance.

Related

Passing sensitive headers in Spring Cloud Gateway

I am migrating my application from Zuul to Spring Cloud Gateway. How can I replace the sensitive header part of below code in Spring Cloud Gateway?
zuul:
routes:
tableau:
path:/test/**
sensitiveHeaders:
url: https://example.com
stripPrefix: false

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.

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

Enable eureka.client.healthcheck

I'm following http://cloud.spring.io/spring-cloud-netflix/spring-cloud-netflix.html to build distributed system with Spring Cloud.
All works as expected apart from Eureka Client Healthcheck.
I have
eureka:
client:
healthcheck:
enabled: true
And pointing my service to nonexisten config_server, this results in
http://myservice:8080/health
{
status: "DOWN"
}
But Eureka server still showing this instance as UP and keep sending traffic to it.
What am I missing?
spring-boot: 1.2.8.RELEASE
spring-cloud-netflix : 1.0.4.RELEASE
You have to explicitly set eureka.client.healthcheck.enabled=true to link the Spring Boot health indicator to the Eureka registration. Source code reference: here.
Ok, I think I found it.
According to https://jmnarloch.wordpress.com/2015/09/02/spring-cloud-fixing-eureka-application-status/ this feature will only be available on Spring Cloud 1.1.
To make it work with 1.0.4 I need to implement my own HealthCheckHandler.
Thanks #xtreme-biker for bringing up Spring Cloud version issue.

Zuul filter requests

I am using Zuul as reverse proxy deployed as a service using Spring Boot. And I have a configuration like:
zuul:
routes:
home:
path: /**
url: localhost:8080
But I want to use the /routes,/info,/health endpoints of the zuul server. Also I want add some endpoints to the zuul server. The problem is that I lost those endpoints because all requests are routed to localhost:8080.
ignoredPatterns in the latest version of ZUUL can help prevent reaching the /** mapping:
zuul:
ignoredPatterns: "/routes/**,/info/**,/custom/**"

Resources