I'm starting with spring cloud.
I created 3 application, one is for discovery service, one for gateway and one is a service.
I'm not using actually spring cloud config and any load balacing
For my discovery
server.port=8761
spring.application.name=discovery-service
eureka.instance.hostname=localhost
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false
eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/
For my gateway
#Port for Registry service
server.port=8080
spring.application.name=gateway-service
spring.cloud.gateway.discovery.locator.enabled=true
spring.cloud.gateway.routes[0].id=hostel-service
spring.cloud.gateway.routes[0].uri=lb://hostel-service
spring.cloud.gateway.routes[0].predicates[0]=Path=/hostels/**
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
For my hostels service
server.port=9000
spring.application.name=hostel-service
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
I see then hostel service is registered in the discovery service
Registered instance HOSTEL-SERVICE/192.168.102.129:hostel-service:9000
with status UP (replication=false)
See it to when i go to http://localhost:8761/
When I try to call
http://localhost:8080/hostels
or
http://localhost:8080/hostel-service/hostels
I get a 404 error
If I do
http://localhost:9000/hostels
I get good results
Edit
Code on github
https://github.com/mctdi/hostel
https://github.com/mctdi/gateway
https://github.com/mctdi/discovery
The hostels app registers in Service Discovery, but the gateway app doesn't. Add 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client' to you implementation dependencies in build.gradle - it will then register in Eureka and the http://localhost:8080/hostels request will be routed to the hostels app.
Related
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
I'm using Eureka Server where every microservice gets registered as soon it gets online.
Now I want to use Zuul to create a gateway proxy.
Zuul works if I provide routes manually:
zuul.routes.ms1.url=http://localhost:8901
zuul.routes.ms2.url=http://localhost:8902
ribbon.eureka.enabled=false
I want Zuul to auto pick routes from Eureka as soon new micro-services is up and registered with Eureka.
I tired adding #EnableAutoDiscovery to Zuul Initalization class
and setting ribbon.eureka.enabled=true after removing routes but nothing worked.
If you give eureka.client.serviceUrl.defaultZone in your properties in zuul service, zuul will take all services which is registered to eureka server.
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}}
I am not experienced in spring micro services and zuul configuration so I will need some help.
I have a microservice running on jhipster-registry and I am trying to access the microservice from my application through the gateway.
In my application I have this service in the current routes:
If I am accessing the service when my application is started as a spring boot app everything works fine; but when I deploy my application on tomcat the same request returns 404.
Here is the zuul config :
zuul:
routes:
assessmentapi:
path: /assessmentapi/**
serviceId: assessmentapi
url: http://192.168.80.44:8081/assessment-api
and http get request
$http.get('/assessmentapi/main/....)
You should not write the URL part in your configuration. As we can see on your gateway screenshot, the gateway already knows the service's IP thanks to Eureka and the Registry. IP addresses should never go into the config as those are determined dynamically.
I am rewriting a Spring MVC system.
The system is something like this in simple:
[Gateway<->Backend Services<->Databases], where Gateway is a controller simply for authentication and forwarding the requests to Backend services.
The Backend services will be refactored to micro-services. I will use Eureka service to do registration for each of them. So eventually the architecture will be: [Gateway <-> Eureka <-> Backend micro-services <-> Databases]. The Gateway will lookup the registries from Eureka server and call the micro services.
However, the Gateway is not a spring boot application(and will NOT be rewritten as Spring boot), thus I don't believe Spring's eureka features (#EnableEurekaClient , DiscoveryClient, ect.) can be adopted easily as the examples do. Actually I tried adding the eureka client annotation to Gateway's controller, which caused my application collapsed.
Moreover, Ribbon is needed in the Gateway for client side loading balancing. But the same concern is as above.
//Update on 1st Nov.
I have set up an Eureka server and a client, both of which are written in spring boot. I am using these two application for my Spring MVC testing. The server and client are running well.
Server's configuration application.properties is as below
server.port=8761
spring.application.name=service-itself
eureka.client.service-url.default-zone=http://localhost:8761/eureka/
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=false
logging.level.com.netflix.eureka=OFF
logging.level.com.netflix.discovery=OFF
client's is as below: application.yml
spring:
application:
name: say-hello
server:
port: 8090
eureka:
client:
service-url:
defaultZone: http://${eureka.host:localhost}:${eureka.port:8761}/eureka/
When accessing the Eureka dashboard localhost:8761, I can see that client has been registered.
For my Spring MVC gateway, as it is not a Spring boot project, so I copied the example to my project simply for testing whether it can connect to the Eureka server and retrieve the registered the instance of "say-hello" client. Unfortunately, it cannot do so with saying "Cannot get an instance of example service to talk to from eureka" which is printed at line 76 in the example class.
Here is the eureka-client.properties placed in gateway's classpath. I can confirmed that the Client class is reading the config file.
eureka.name=gatewayEurekaClient
eureka.vipAddress=say-hello
eureka.port=8761
eureka.preferSameZone=true
eureka.preferSameZone=true
eureka.shouldUseDns=false
eureka.serviceUrl.default=http://localhost:8761/eureka
eureka.serviceUrl.defaultZone=http://localhost:8761/eureka
Moreover, this is the debug information when new DiscoveryClient(applicationInfoManager, clientConfig); is being executed
instanceInfo InstanceInfo (id=234)
actionType null
appGroupName "UNKNOWN" (id=246)
appName "GATEWAYEUREKACLIENT" (id=247)
asgName null
countryId 1
dataCenterInfo PropertiesInstanceConfig$1 (id=248)
healthCheckExplicitUrl null
healthCheckRelativeUrl "/healthcheck" (id=253)
healthCheckSecureExplicitUrl null
healthCheckUrl "http://A156N7AB89AXNZQ:8761/healthcheck" (id=254)
homePageUrl "http://A156N7AB89AXNZQ:8761/" (id=255)
hostName "A156N7AB89AXNZQ" (id=256)
instanceId "A156N7AB89AXNZQ" (id=256)
ipAddr "10.209.66.64" (id=257)
isCoordinatingDiscoveryServer Boolean (id=258)
isInstanceInfoDirty false
isSecurePortEnabled false
isUnsecurePortEnabled true
lastDirtyTimestamp Long (id=260)
lastUpdatedTimestamp Long (id=263)
leaseInfo LeaseInfo (id=264)
metadata ConcurrentHashMap<K,V> (id=266)
overriddenstatus InstanceInfo$InstanceStatus (id=267)
port 8761
secureHealthCheckUrl null
securePort 443
secureVipAddress null
secureVipAddressUnresolved null
sid "na" (id=270)
status InstanceInfo$InstanceStatus (id=271)
statusPageExplicitUrl null
statusPageRelativeUrl "/Status" (id=272)
statusPageUrl "http://A156N7AB89AXNZQ:8761/Status" (id=273)
version "unknown" (id=274)
vipAddress "say-hello" (id=275)
vipAddressUnresolved "say-hello" (id=275)
I am running out of idea. Can anyone please give a hand on this problem?
Ribbon (https://github.com/Netflix/ribbon) and Eureka (https://github.com/Netflix/eureka) can work without Spring (and that is the way they were developed in the first place) but you will need to put a bit more effort into configuring everything to your needs.
Support for Ribbon and Eureka in Spring is part of the Spring Cloud project (and mvn group id), not Spring Boot. I don't think boot is mandatory. Ribbon and Eureka themselves are provided by Netflix.
For ribbon, you need to define your own #LoadBalanced RestTemplate #Bean anyway. #EnableDiscoveryClient should work as long as the dependencies have spring cloud eureka and your class is a #Configuration class.
Short answer is - why not try a quick test? :).