Spring boot application ,accessing routs with gateway service gives white label error? - spring

Hey Guys I was developing a simple project with spring boot, which has 2 services user and blogs and I am using eureka server and I tried to implement a gateway service and it also got registered on the eureka server also but I cannot access the route paths of either user or blog service can anyone please help me with this. This the application.yml file for the gateway service.
server:
port: 3030
spring:
application:
name: gateway-service
cloud:
gateway:
routes:
- id: userModule
uri: http://localhost:3001/
predicates:
- Path=/users/**
- id: blogModule
uri: http://localhost:3002/
predicates:
- Path=/blogs/**
eureka:
client:
serviceUrl:
defaultZone: http://localhost:3000/eureka
registerWithEureka:
- true
fetchRegistry:
- true

Related

Using the auth filter in an api gateway Spring boot

I made 2 microservices running on a cluster in Kubernetes , I was able to make an API gateway using spring cloud to call those microservices , and I made a JWT Authorization and Authentication filters in another project .
My question is, how can I integrate these filters in my API gateway to authorize the access to my microservices
spring:
cloud:
gateway:
routes:
- id: r1
uri: http://192.168.49.2:30288/
predicates:
- Path= /api1/**
- id: r2
uri: http://192.168.49.2:30289/
predicates:
- Path= /api2/**
discovery:
enabled: false
server:
port: 8888

How Eureka Server and Spring Cloud API Gateway communicates with each other?

In Spring Boot Microservices architecture, we generally register our each microservice (its many instances) into Eureka server by doing eureka.client.register-with-eureka=true, eureka.client.fetch-registry=true and eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka. So Eureka acts as service registry for these services (service-name, hostname and its IP).
Spring Cloud API Gateway acts as a single point of entry for any microservice call. It can work as a proxy service to route a request to the concerned microservice, abstracting the producer details. It has route information only, then how Spring Cloud API gateway comes to know which microservice instance to call to? How API Gateway and Eureka communicates and load balance?
spring:
application:
name: api-gateway
cloud:
gateway:
discovery:
locator:
enabled: true
lower-case-service-id: true
routes:
- id: user-service
uri: lb://user-service
predicates:
- Path=/users/**
- id: order-service
uri: lb://department-service
predicates:
- Path=/departments/**
spring:
cloud:
gateway:
discovery:
locator:
enabled: true
With the Discovery Locator enabled in API Gateway, you do not have to manually configure the routes unless absolutely needed.
The way API Gateway knows which Eureka Service to route the incoming request to is as follows:
Assuming,
Orders Service runs on http://localhost:8080
API Gateway runs on http://localhost:8082
Eureka Service name for Orders Service - order-service
Then if order-service getOrders endpoint: http://localhost:8080/orders, then with Discovery Locator enabled the request needs to be routed through the API gateway with the following URL: https://localhost:8082/order-service/orders, i.e., {ApiGatewayHost}/{EurekaServiceId}/{ActualEndpoint}.
Register Gatway to Eureka Server

Is it possible to register with eureka with Discovery first?

I'm trying to achieve a discovery first spring cloud config mode.
This is my client bootstrap.yml
server:
port: 9090
spring:
application:
name: test-config
cloud:
config:
fail-fast: true
discovery:
enabled: true
serviceId: configservice
eureka:
client:
register-with-eureka: true
serviceUrl.defaultZone: http://localhost:8011/eureka/
The configuration is fetched ok, the client starts but is not registered with eureka
So when I look at the eureka dashboard i see only the config service not the client app. The documentation does not state explicitly that this does not work(if I understand it correctly).
Is this on purpose?
Is this a bug?
Is there a possibility to achieve this setup?
Does your main class include: #EnableEurekaClient?
Could you verify your yml properties are properly spaced?

Netflix Turbine does not display cluster hystrix stream

I tried to use Netflix Turbine (1.1.5) to group hystrix (1.1.5) streams.
Turbine App configuration:
spring.application.name=moritoring_server
server.port=8989
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka
eureka.instance.preferIpAddress=true
turbine.aggregator.clusterConfig=MPI_Services
turbine.appconfig=MPI_Services
Healthy-checks App which used hystrix and need to be displayed in Turbine Dashboard:
spring.application.name=health_checks_service
spring.cloud.config.enabled=true
spring.cloud.config.discovery.enabled=true
spring.cloud.config.discovery.serviceId=MPI_Services
server.port=8081
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka
eureka.instance.preferIpAddress=true
eureka.instance.metadataMap.cluster=MPI_Services
I can see the cluster from Eureka as below and individual Hystrix stream from Turbine is fine,
However, I cannot use cluster in Turbine stream and it seems keep loading,
Could someone please advise me how to fix the issue?
Thanks,
Sean
Several points to check here.
1) The application that you are monitoring is providing hystrix.stream on port 8081. Try setting eureka.instance.metadataMap.management.port to 8081 in the application so that Turbine could be able to figure out the correct port. Check this one for detials.
2) I would try avoiding mixing the upper and lower case letters in the cluster names
3) When checking out the Hystrix Dashboard for shoing Turbine stream, make sure you call the demo app so that some statistics get generated. Dashboard remains empty (loading) until first messages pass through the Hystrix command
4) Wait until the Turbine app actually discovers the application cluster (check for "Found hosts" and "Hosts up" messages in the Turbine application logs). This happens after a certain timeout interval, not immediately after application startup
Here is a config that worked for me with Spring Cloud Dalston.SR1
Demo application.yml:
management:
security:
enabled: false
port: 8081
hystrix:
enabled: true
Demo bootstrap.yml:
spring:
application:
name: demo-service
cloud:
config:
discovery:
enabled: true
serviceId: config-service
eureka:
client:
register-with-eureka: false
serviceUrl:
defaultZone: http://localhost:8761/eureka/
instance:
hostname: ${APPLICATION_DOMAIN:localhost}
nonSecurePort: 8090
metadataMap:
management.port: 8082
Hystrix Dashboard & Turbine bootstrap.yml
spring:
application:
name: hystrix-service
cloud:
config:
discovery:
enabled: true
serviceId: config-service
eureka:
client:
register-with-eureka: false
serviceUrl:
defaultZone: http://localhost:8761/eureka/
Hystrix Dashboard & Turbine application.yml
...
turbine:
aggregator:
clusterConfig: DEMO-SERVICE
appConfig: demo-service
After all pieces of the solution are started, the Hystrix dashboard is available at
http://localhost:8989/hystrix
The Turbine stream URL to use is then
http://localhost:8989/turbine.stream?cluster=DEMO-SERVICE
The complete Hystrix Dashboard and Turbine URL of the dashboard:
http://localhost:8989/hystrix/monitor?stream=http%3A%2F%2Flocalhost%3A8989%2Fturbine.stream%3Fcluster%3DDEMO-SERVICE

Zuul Routing when using eureka services

I have a reasonably simple Spring Cloud Netflix setup. We are using Zuul as a reverse proxy and Eureka for service discovery and registry. we have legacy services we are slowly choking out. We have many simple services that have their endpoints configured like this:
{host}:{port}/{service-name}/**
so now when each service is registered with eureka, and subsequently has a route added to Zuul, the zuul endpoint looks like this:
{zuul-host}:{zuul-port}/{service-name}/{service-name}/**
I want to stop Zuul from striping the prefix off the routed URIs for eureka services so that my zuul endpoints look like this:
{zuul-host}:{zuul-port}/{service-name}/**
and forward to:
{zuul-host}:{zuul-port}/{service-name}/**
I would like this to be done in a way such that I do not have to add configs for each and every service.
I would have assumed that zuul.strip-prefix would have done the trick, but that doesn't appear to be the case.
current Zuul application.yml:
zuul:
routes:
oldservice:
path: /oldservice/**
url: http://oldservice-host:9080/api/v1/oldservice
strip-prefix: false
eureka:
client:
serviceUrl:
defaultZone: http://eureka-host:8761/eureka/
Anyone have a suggestion for how I can configure zuul in this way?
Since you are registering your service with eureka why not use the service-id for routing like below.
the service-id is the id that your service gets registered in Eureka with.
zuul:
routes:
path: /oldservice/**
service-id: oldservice
strip-prefix: false
eureka:
client:
serviceUrl:
defaultZone: http://eureka-host:8761/eureka/
For your current scenario I moved the strip-prefix inside the routes I have it like that in my system you can try that.
zuul:
routes:
oldservice:
path: /oldservice/**
url: http://oldservice-host:9080/api/v1/oldservice
strip-prefix: false
eureka:
client:
serviceUrl:
defaultZone: http://eureka-host:8761/eureka/

Resources