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
Related
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
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
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 want to be able to proxy with Zuul running on a Spring Boot server listening to port X to port Y where an nginx is listening on the same machine. I want to send the same URL, parameters, etc.
The reason I am doing this is that using a ZuulFilter which is doing some checks.
For example I want to get to localhost:8943/humans/get/1 and send the request to localhost:8080/humans/get/1
Thanks in advance.
Something like this should work.
zuul:
routes:
humans:
path: /humans/**
url: http://localhost:8080
I've managed to do it with the following configuration:
zuul:
routes:
services:
path: /**
url: http://localhost:8043/