I am working with Eureka/Zuul and Springboot microservices.
While mapping multiple instances of same application to Zuul gateway, i am using serviceId attribute.
Here i had shared my application.yml of zuul project.
server:
port: 8093
servlet:
context-path: /apigateway
spring:
application:
name: zuul-proxy
zuul:
sensitiveHeaders: Cookie,Set-Cookie
host:
socketTimeoutMillis: 60000
routes:
authenticator-oauth:
path: /oauth/
url: http://localhost:8092/authenticator/oauth
sample-resource-server:
path: /sample/
serviceId: sample
stripPrefix: false
sample:
ribbon:
NIWSServerListClassName: com.netflix.loadbalancer.ConfigurationBasedServerList
listOfServers: http://localhost:8096,http://localhost:8097
ConnectTimeout: 60000
ReadTimeout: 60000
MaxTotalHttpConnections: 500
MaxConnectionsPerHost: 100
authenticator:
ribbon:
NIWSServerListClassName: com.netflix.loadbalancer.ConfigurationBasedServerList
listOfServers: http://localhost:8092, http://localhost:8091
ConnectTimeout: 1000
ReadTimeout: 5000
MaxTotalHttpConnections: 500
MaxConnectionsPerHost: 100
eureka:
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://localhost:8094/eureka/
instance:
preferIpAddress: true
I am able to run my authenticator application.
Also i am able to run my sample application on both port(8096/8097) with load balancing .
Here as you can see i had mapped authenticator service using URL and it's working fine.
url: http://localhost:8092/authenticator/oauth
But when i had mapped it with service id as below code, it's not able to redirect with actual authentication service url.
authenticator-oauth:
path: /authenticator/**
serviceId: authenticator
stripPrefix: false
In both these cases, i am hitting same URL as below
http://localhost:8093/apigateway/oauth/token.
Why authentication service or oauth/token end point behave differently compare to normal application?
Any help will appreciated.
In order to register multiple instance of same micro-service you have to do nothing
in ZUUL API GATEWAY.
Add a property in the micro-service itself for which you are creating multiple instance.
server:
port: ${PORT:0}
eureka:
instance:
instance-id: ${spring.application.name}:${spring.application.instance_id:${random.value}}
Every time you will start same service it will start on unique port
It will register itself with eureka discovery service
Load Balancing will be done automatically since ribbon comes built in with Zuul
Related
Is there a way via configuration to blacklist specific ip addresses from registering as microservices with Spring Eureka cloud discovery? It seems that each time I restart my discovery service an unrecognized ip instance is registering as a microservice. From the attached image I would expect that only a single instance be present rather than the two shown.
Currently the application.yml file is configured as follows:
---
# This default profile is used when running a single instance completely standalone:
#spring:
# profiles: default
server:
port: 8010
eureka:
instance:
hostname: eurekahost
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
security:
basic:
enabled: false
user:
name: user # login username
password: password
Although this is not my ideal solution since I prefer to do this via configuration, I found that I can de-register the service via Eureka's REST API.
I use spring boot 2.0.X and want to use an admin-server that automatically detects other services registered at Eureka. I have followed this guide to the letter, but none of the applications are shown in the admin console. All applications are registered with Eureka successfully.
Admin-server configuration:
server:
port: 8762
spring:
application:
name: admin-server
boot:
admin:
discovery:
ignored-services: admin-server
#The admin server will automatically pick up all services at eureka and register them to itself.
eureka:
instance:
leaseRenewalIntervalInSeconds: 10
health-check-url-path: /actuator/health
metadata-map:
startup: ${random.int} #needed to trigger info and endpoint update after restart
client:
registryFetchIntervalSeconds: 5
registerWithEureka: true #default true
fetchRegistry: true #default true
serviceUrl:
defaultZone: http://localhost:8761/eureka/
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: ALWAYS
Eureka server configuration:
server:
port: 8761
spring:
application:
name: discovery-server
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://localhost:8761/eureka/
Some thoughts:
We migrated from spring boot 1.5.x to 2.0.x, is there a problem with
security? We don't use spring-security anywhere but I read that some
http endpoints are not "reachable" or "active" by default anymore. But I see no errors or warning in the logf of the admin server or eureka server about this.
None of my other applications have the spring boot admin starter client dependency in their pom, because I don't want THAT to be the part that is responsible for registering ith the admin console, I want it be done dynamically through Eureka
All applications, except the admin server and the eureka server, use
the config-server to fetch their configuration. Does this cause
problems?
The application.yml that all other applications get from the config server contains the following:
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
spring:
boot:
admin:
url: http://localhost:8762
management: #exposing all endpoints is not safe for production, especially not if spring security gets involved
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: ALWAYS
I had the same issue when upgrading to SBA2.
Versions of spring-boot, spring-cloud and SBA should match. I used:
spring-boot: 2.0.7.RELEASE
spring-cloud: Finchley.SR2
SBA: 2.0.4
In my case the trick was to use spring-boot-admin-starter-server as dependency instead of plain dependencies (spring-boot-admin-server, spring-boot-admin-server-ui, spring-boot-admin-server-cloud) as it is descriped here:
https://github.com/codecentric/spring-boot-admin/issues/776
I using spring zuul for managing API_Gateway. But I have the basic problem that can’t forward requests to a specific path. multiple addresses exist in my services that is unchangeable and I will forward from a specific address. I prefer don't use “Zuulfilter” but used that doesn’t useful.
users request:(it's ok)
Browser Request: gateway.com/api1/user → gateway → apihost.com/api1/user
swagger request:(it's fail)
Browser Request: gateway.com/api1/swagger → gateway → apihost.com/swagger-ui.html
I using service_discovery (eureka) and My application.yml file configration is:
Zuul:
routes:
swagger:
path: /api1/swagger
service_id: api1
url: forward:/swagger-ui.html#/
users:
path: /api1/user/**
service_id: api1
stripPrefix: false
But i see at debug mode:
2019-01-17 11:28:46.437 DEBUG 77407 --- [nio-8181-exec-4] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Did not find handler method for [/swagger-ui.html#/api1/swagger]
2019-01-17 11:28:46.437 DEBUG 77407 --- [nio-8181-exec-4] a.e.w.s.ControllerEndpointHandlerMapping : Looking up handler method for path /swagger-ui.html#/api1/swagger
2019-01-17 11:28:46.437 DEBUG 77407 --- [nio-8181-exec-4] a.e.w.s.ControllerEndpointHandlerMapping : Did not find handler method for [/swagger-ui.html#/api1/swagger]
I also added a route filter (Zuulfilter) for directly call address from service but the response is different. That use anyway to use Zuul configuration to forwarding done ( as regards I using service discovery) if not is exist sample code for development servlet filter?
My friend Eureka is for service discovery and Zuul is API gate way.
In the Zuul client add the configuration as shown below in application.yaml.
Try this way: -
server:
port: 9999
eureka: #tells about the Eureka server details and its refresh time
instance:
leaseRenewalIntervalInSeconds: 1
leaseExpirationDurationInSeconds: 2
client:
serviceUrl:
defaultZone: http://127.0.0.1:8761/eureka/
spring:
application:
name: zuul-server
zuul:
#Service will be mapped under the /api URI
routes:
service1:
service-id: id4
path: /trade/**
url: http://localhost:8091
strip-prefix: false
service2:
service-id: id5
path: /**
url: http://localhost:8096
strip-prefix: false
According to section 3.2 of the Spring Cloud Consul manual:
An HTTP Check is created by default that Consul hits the /health
endpoint every 10 seconds.
However, the log of my application reveals that this health check is missing. The property http should have a valid url and interval should have 10s, both are null:
Registering service with consul:
NewService{id='test-service-local-8081', name='test-service', tags=[],
address='localhost', port=8081, enableTagOverride=null,
check=Check{script='null', interval='null', ttl='30s', http='null',
tcp='null', timeout='null', deregisterCriticalServiceAfter='null',
tlsSkipVerify=null, status='null'}, checks=null}
Also, when I make my health endpoint return "status: down", consul still reports that my service is fine.
How do I add the HTTP check to /health on registration of the Spring Boot service with Consul?
I am using the following properties:
management:
endpoints:
web:
base-path: /manage
spring:
application:
name: test-service
cloud:
consul:
host: consul
port: 8500
discovery:
healthCheckInterval: 10s
healthCheckPath: "${management.endpoints.web.base-path}/health"
heartbeat:
enabled: true
hostname: localhost
Edit: It turns out the heartbeat.enabled=true property removes the default HTTP check. When removing this property, we can see the HTTP check in the log:
Registering service with consul:
NewService{id='test-service-local-8081', name='test-service',
tags=[], address='erwins-mbp.home', port=8081, enableTagOverride=null,
check=Check{script='null', interval='1s', ttl='null',
http='http://mbp.home:8081/manage/health', tcp='null',
timeout='null', deregisterCriticalServiceAfter='null',
tlsSkipVerify=null, status='null'}, checks=null}
So, now, the question is, with heartbeat enabled, how to I register a HTTP check from Spring Boot to Consul?
I have a local eureka server and one client
Eureka:
server:
port: 1111
eureka:
instance:
prefer-ip-address: true
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://127.0.0.1:1111/eureka/
server:
waitTimeInMsWhenSyncEmpty: 0
Client:
eureka:
instance:
prefer-ip-address: true
client:
serviceUrl:
defaultZone: http://127.0.0.1:1111/eureka/
I have 2 problems:
1) Eureka server throws in log:
NullPointerException:
at com.netflix.eureka.resources.StatusResource.isReplicaAvailable
2) The client connecting with Eureka, but after some time I see in his log next:
RedirectingEurekaHttpClient : Request execution error
javax.ws.rs.WebApplicationException: null at com.netflix.discovery.provider.DiscoveryJerseyProvider.readFrom(DiscoveryJerseyProvider.java:110)
RetryableEurekaHttpClient : Request execution failure
DiscoveryClient : DiscoveryClient_MW/192.168.0.100:client:8080 - was unable to send heartbeat!
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
In log Eureka I see:
InstanceRegistry : DS: Registry: lease doesn't exist, registering resource: CLIENT - 192.168.0.100:client:8080
InstanceResource : Not Found (Renew): CLIENT - 192.168.0.100:client:8080
In Eureka web console the client has a UP status, but also there is a big inscription:
RENEWALS ARE LESSER THAN THE THRESHOLD. THE SELF PRESERVATION MODE IS
TURNED OFF.THIS MAY NOT PROTECT INSTANCE EXPIRY IN CASE OF
NETWORK/OTHER PROBLEM
Although connection is working and I can get link to my client throught Eureka.
Could you explain what it means and how I can get rid from that?
serviceUrl:
defaultZone: http://127.0.0.1:1111/eureka/
in client setting YML, you should add space before "defaultZone" like this:
serviceUrl:
defaultZone: http://127.0.0.1:1111/eureka/
else defaultZone is same level with serviceUrl.
thanks