How to route to another port with Zuul - microservices

I am trying to route all of my microservices to one route with the port 8080 (shop)
I have a microservice articlemicroservice that is connected to an Eureka Server (port:8084).
I do also have zuulservice connected to Eureka (running on Port 8888).
Example:
http://localhost:8084/articles should be available on http://localhost:8080/articles
I tried to configure it in my application.yml in my zuul server like this:
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8888/eureka
server:
port: 8079
zuul:
routes:
articlemicroservice:
path: /*
serviceId: articlemicroservice
url: http://localhost:8080/
Important: Shop (Port:8080) is not connected to Eureka.
ArticleMicroService:
server.port=8084
spring.application.name=articlemicroservice
eureka.client.serviceUrl.defaultZone=http://localhost:8888/eureka/
eureka.client.fetchRegristry=true
eureka.instance.preferIpAddress=true
ShopMicroService:
server.port=8080
spring.application.name=shopmicroservice
Edit: The example with the yml did not work.
Edit:
Eureka Server:
server.port=8888
spring.application.name=eurekaserver
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.service-url.defaultZone=http://localhost:8888/eureka/
eureka.instance.lease-expiration-duration-in-seconds:2

I think you need one GatewayApplication on port 8080, this application will proxy requests for other applications deployed under any other ports
Run Zuulproxy on 8080
Run ShopMicroService on ex. 8081
Run ArticleMicroService on 8084
Configure zuul routes like:
zuul:
routes:
articlemicroservice:
path: /article/**
url: http://localhost:8084/
shopmicroservice:
path: /shop/**
url: http://localhost:8081/
awesome example : https://github.com/sqshq/piggymetrics
OR I think you can #EnableZuulProxy in ShopMicroService
zuul:
routes:
articlemicroservice:
path: /article/**
url: http://localhost:8084/
I don't think there is a way to make ZUUL works on 8079

Related

Deployment issue on Heroku : zuul + eureka + microservices

Thanks for taking the time to read my post.
My issue is as such. I have 2 microservices (auth-service and image-service) deployed on Heroku, as well as a server Eureka and a gateway Zuul.
In local, all of this works.
However, when deployed, the same calls give me 404 errors : for example :
zuul is deployed on port 8762 in local,
so http://localhost:8762/images/user/create works, it points to http://localhost:8200/user/create of the image-service.
Deployed, https://croquis-time-image.herokuapp.com/user/create works, but https://croquis-time-zuul.herokuapp.com/images/user/create throws a 404 error.
On eureka however, all my services are registered, so the trouble doesn't come from there. I thought perhaps zuul didn't manage to get all the services from Eureka, but I'm not sure how to check.
More information :
application.yml of zuul deployed :
server:
port: 8762
eureka:
client:
serviceUrl:
defaultZone: https://croquis-time-eureka.herokuapp.com/eureka/
instance:
hostName: croquis-time-eureka.herokuapp.com
zuul:
#Service will be mapped under the /api URI
prefix: /api
# Uncomment to disable auto-registering all services read from Eureka
# ignoredServices: '*'
routes:
image-service:
path: /images/**
serviceId: image-service
auth-service:
path: /auth/**
serviceId: auth-service
stripPrefix: false
sensitiveHeaders: Cookie,Set-Cookie
spring:
application:
name: zuul-server
security:
jwt:
uri: /auth/**
prefix: Bearer
expiration: 86400
header: Authorization
secret: *****************
The application.yml of eureka deployed
server:
port: 8761
eureka:
instance:
hostname: croquis-time-eureka.herokuapp.com
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: https://croquis-time-eureka.herokuapp.com/eureka/
spring:
application:
name: eureka-server
The image service I'm trying to call :
server:
port: 8200
eureka:
client:
serviceUrl:
defaultZone: https://croquis-time-eureka.herokuapp.com/eureka/
instance:
hostName: croquis-time-eureka.herokuapp.com
spring:
application:
name: image-service
jpa:
showSql: true
hibernate:
ddlAuto: update
datasource:
url: jdbc:mysql://***********:3306/croquis-time
username: ******************
password: ****************
I have tried removing and adding the "ignored-services" from zuul to see if that was the problem, but it didn't change anything.
I'm very willing to edit my question with more information if you require more, I'm not sure where is the origin of the problem, so I'm a bit at a loss as to what to add.
Thanks !
you have an issue with the configuration of .yml in zuul server
Your .yml of zuul server must be:
instance:
hostName: croquis-time-zuul.herokuapp.com
And your .yml of image must be:
instance:
hostName: croquis-time-image.herokuapp.com
because instance.hostname is the host of your application acting as the eureka client. if you need more information please visit: https://blog.heroku.com/managing_your_microservices_on_heroku_with_netflix_s_eureka

Spring cloud Zuul url configuration

I am trying to run an example with zuul and Eureka server.
Below are my configurations:
eureka-service
server.port=8761
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
logging.level.com.netflix.eureka=OFF
logging.level.com.netflix.discovery=OFF
eureka -client (bootstrap.properties):
spring.application.name=ab
management.server.port=9001
management.server.address: 127.0.0.1
server.port=8081
edge-service(zuul) :
zuul.routes.ab.url=http://localhost:8081
ribbon.eureka.enabled=false
spring.application.name=API-Gateway
eureka.client.eureka-server-port=8761
server.port=8080
While I am hitting the URL http:localhost:8080/clientapi, I get a white label error page, what configuration seems to be missing, as I could see edge-service, as well as eureka-client, registered correctly with the eureka -server.
I am using spring boot: 2.1.4.
Let me show you my example:
eureka in application.yml file:
server:
port: 8761
eureka:
client:
register-with-eureka: false
fetch-registry: true
instance-info-replication-interval-seconds: 10
server:
eviction-interval-timer-in-ms: 50000
wait-time-in-ms-when-sync-empty: 5
zuul:
zuul.routes.1.url=http://localhost:8081
zuul.routes.2.url=http://localhost:8082
zuul.prefix=/client
zuul.host.max-per-route-connections=10
zuul.host.max-total-connections=10
I have 2 services (1 - localhost:8081 and 2 - localhost:8082)
You need annotate main class Zuul:
#EnableZuulProxy
#EnableDiscoveryClient
Then start application. When you go to
localhost/8070/client/1
you will redirect to first service (localhost:8081)
When you go to
localhost/8070/client/2
I hope it will help you.
you will redirect to second service (localhost:8082)

Error "Load balancer does not have available server for client" when using zuul and eureka

I have a couple of microservices on Heroku - eureka-server, Zuul server and some app services.
While I am trying to reach any of my services, for example, "service1" via Zuul gateway, Zuul is unable to forward the request to the respective service (when I'm trying to run them locally everything works fine).
I've found the following errors in Zuul logs:
com.netflix.zuul.exception.ZuulException: Forwarding error
Caused by: com.netflix.client.ClientException: Load balancer does not have the available server for the client: service1
Below are configurations of my services:
1) "zuul server" application.yml
server:
port: ${PORT:8000}
zuul:
prefix: /api
ignoredServices: '*'
routes:
service1:
path: /path_for_service1/**
serviceId: service1
strip-prefix: false
...
management:
endpoints:
web:
exposure:
include: "*"
eureka:
client:
serviceUrl:
defaultZone: ${EUREKA_URL:http://localhost:5000}/eureka/
2) "eureka server" application.yml
server:
port: ${PORT:5000}
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
3.1) "service1" application.yml
server.port=${PORT:8081}
eureka.client.service-url.defaultZone=${EUREKA_URL:http://localhost:5000}/eureka/
3.2) "service1" bootstrap.yml
spring:
application:
name: service1
All microservices are visible in eureka dashboard.
If I change zuul routes to hard-coded url it works well but it is not what I'm looking for.
zuul:
prefix: /api
ignoredServices: '*'
routes:
service1:
path: /path_for_service1/**
url: http://url_of_service_1
strip-prefix: false
Could you please help me with this issue?
Finally, I've found root cause :)
All services are registered in eureka using heroku hostname by default (like "085930c7-b893-4b34-88a7-6e37fbe7fa0f") which is not accessible outside.
But services are accessible by domain names.
So I just added domain name settings to application.properties of each service (https://blog.heroku.com/managing_your_microservices_on_heroku_with_netflix_s_eureka)
eureka:
instance:
non-secure-port: 80
hostname: ${DOMAIN_NAME}
and now it works.

How to Configure Zuul Multiple instances of one microservice

i'm working in a spring cloud project and i have an eruka service, zull proxy and a microservice with the name defects-service (zull proxy and my defects-service are clients for eurka) and all works fine.
in my zull proxy i have the following configuration :
eureka:
client:
register-with-eureka: true
fetch-registry: true
serviceUrl:
defaultZone: http://localhost:8370/eureka/
instance:
hostname: localhost
zuul:
prefix: /api
routes:
defects-service:
path: /defects-service/**
url: http://localhost:8300
my issue is now i start two instances of my defects-service on diferents ports 8301 and 8302 (registred successfully in eruka service ) but i don't know how to configure my zull proxy to do a load balancing and start redirect requests to my three instances on ports (8300,8301,8302).
note , zull knows only the instance on http://localhost:8300
can anyone please helpe me to resolve this isuue .
Best regards .
Zuul support load balancing out of the box, instead of giving url in your configuration, use serviceId:
zuul:
prefix: /api
routes:
defects-service:
path: /defects-service/**
serviceId: defects-service
the solution of this problem is by using the following config :
zuul:
prefix: /api
routes:
defects-service:
path: /defects-service/**
serviceId: defects-service
after that if you got any error like Hystrix Readed time out.. just add the following config :
hystrix:
command:
default:
execution:
isolation:
thread:
timeoutInMilliseconds: 11000
ribbon:
ConnectTimeout: 10000
ReadTimeout: 10000

Spring cloud with Eureka - Eureka Web UI URL

I have Eureka setup with my spring boot application, and Eureka has a neat web UI built in which I like
Here's my config in application.yml
server:
port: 8081
management:
context_path: /admin
## EUREKA CONFIG ##
eureka:
instance:
hostname: localhost
metadataMap:
instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}}
client:
registerWithEureka: true
fetchRegistry: true
server:
waitTimeInMsWhenSyncEmpty: 0
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
However, the web UI shows up on my eureka server at
http://localhost:8081/
is there a way to change the url of the web ui only to something like
http://localhost:8081/eurekawebui
Thanks
You can set eureka.dashboard.path=/eurekawebui. It defaults to /.

Resources