How to deal with docker deployed spring cloud application mutual access through zuul? - spring-boot

I deployed my spring cloud application in docker,include eureka server,zuul,eureka client. I want to access eureka client via zuul.
Zuul and eureka client are registered at eureka server.I access each application ,it is work. When I access eureka client via zuul, zuul console infomation show java.net.NoRouteToHostException. I don't know why and how to deal with this problem.
Eureka server config is like this.
server:
port: 1020
spring:
application:
name: eureka-server
security:
basic:
enabled: true
user:
name: admin
password: admin
eureka:
client:
fetch-registry: true
register-with-eureka: true
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
instance:
hostname: 192.168.90.183
prefer-ip-address: true
ip-address: 192.168.90.183
server:
enable-self-preservation: false
eviction-interval-timer-in-ms: 5000
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
shutdown:
enabled: true
Zuul config is like this.
server:
port: 8088
spring:
application:
name: gateway
security:
oauth2:
management:
security:
enabled: false
endpoints:
web:
exposure:
exclude: refresh,health,info
ribbon:
ReadTimeout: 20000
SocketTimeout: 20000
zuul:
# sensitiveHeaders: "*"
routes:
tdcm-linyi:
path: /371300/**
serviceId: tdcm
ratelimit:
key-prefix: your-prefix
enabled: true
behind-proxy: true
default-policy:
limit: 100
quota: 1000
refresh-interval: 60
type:
- user
- origin
- url
host:
connect-timeout-millis: 20000
socket-timeout-millis: 20000
#================================eureka setting==============================
eureka:
instance:
instance-id: ${eureka.instance.hostname}:${server.port}
hostname: 192.168.90.183
prefer-ip-address: true
ip-address: 192.168.90.183
lease-expiration-duration-in-seconds: 10
lease-renewal-interval-in-seconds: 5
client:
serviceUrl:
defaultZone: http://admin:admin#${EUREKA_HOST:192.168.90.183}:${EUREKA_PORT:1020}/eureka
fetch-registry: true
register-with-eureka: true
Eureka client config is like this.
spring:
application:
name: tdcm
banner:
charset: UTF-8
http:
encoding:
charset: UTF-8
enabled: true
force: true
messages:
encoding: UTF-8
mvc:
throw-exception-if-no-handler-found: true
# Server
server:
port: 8926
tomcat:
uri-encoding: UTF-8
#================================eureka settinig==============================
eureka:
instance:
instance-id: ${eureka.instance.hostname}:${server.port}
hostname: 192.168.90.183
prefer-ip-address: true
ip-address: 192.168.90.183
lease-expiration-duration-in-seconds: 10
lease-renewal-interval-in-seconds: 5
client:
serviceUrl:
defaultZone: http://admin:admin#${EUREKA_HOST:192.168.90.183}:${EUREKA_PORT:1020}/eureka
fetch-registry: true
register-with-eureka: true
My test operate is like this.
I access the zuul by http://192.168.90.183:8088 ,it works well.
I access the eureka client by http://192.168.90.183:8926/getCityCenter , it works well.
When I access the eureka client via zuul by
http://192.168.90.183:8088/371300/getCityCenter , it doesn't work.
The console show the information like this.
03-29 01:55:27.229 INFO [c.n.loadbalancer.DynamicServerListLoadBalancer] - DynamicServerListLoadBalancer for client tdcm initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=tdcm,current list of Servers=[192.168.90.183:8926],Load balancer stats=Zone stats: {defaultzone=[Zone:defaultzone; Instance count:1; Active connections count: 0; Circuit breaker tripped count: 0; Active connections per server: 0.0;]
},Server stats: [[Server:192.168.90.183:8926; Zone:defaultZone; Total Requests:0; Successive connection failure:0; Total blackout seconds:0; Last connection made:Thu Jan 01 00:00:00 UTC 1970; First connection made: Thu Jan 01 00:00:00 UTC 1970; Active Connections:0; total failure count in last (1000) msecs:0; average resp time:0.0; 90 percentile resp time:0.0; 95 percentile resp time:0.0; min resp time:0.0; max resp time:0.0; stddev resp time:0.0]
]}ServerList:org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList#3275110f
03-29 01:55:28.201 INFO [com.netflix.config.ChainedDynamicProperty] - Flipping property: tdcm.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
03-29 01:55:28.545 INFO [org.apache.http.impl.execchain.RetryExec] - I/O exception (java.net.NoRouteToHostException) caught when processing request to {}->http://192.168.90.183:8926: No route to host (Host unreachable)
03-29 01:55:28.546 INFO [org.apache.http.impl.execchain.RetryExec] - I/O exception (java.net.NoRouteToHostException) caught when processing request to {}->http://192.168.90.183:8926: No route to host (Host unreachable)
03-29 01:55:28.546 INFO [org.apache.http.impl.execchain.RetryExec] - Retrying request to {}->http://192.168.90.183:8926
03-29 01:55:28.546 INFO [org.apache.http.impl.execchain.RetryExec] - Retrying request to {}->http://192.168.90.183:8926
03-29 01:55:28.547 INFO [org.apache.http.impl.execchain.RetryExec] - I/O exception (java.net.NoRouteToHostException) caught when processing request to {}->http://192.168.90.183:8926: No route to host (Host unreachable)
03-29 01:55:28.548 INFO [org.apache.http.impl.execchain.RetryExec] - Retrying request to {}->http://192.168.90.183:8926
03-29 01:55:28.555 ERROR [c.t.gateway.component.exception.ProducerFallback] - s:tdcm
03-29 01:55:28.556 ERROR [c.t.gateway.component.exception.ProducerFallback] - exception: null
03-29 01:55:29.549 ERROR [c.t.gateway.component.exception.ProducerFallback] - s:tdcm
03-29 01:55:29.550 ERROR [c.t.gateway.component.exception.ProducerFallback] - exception: null
03-29 01:55:29.550 ERROR [c.t.gateway.component.exception.ProducerFallback] - s:tdcm
03-29 01:55:29.551 ERROR [c.t.gateway.component.exception.ProducerFallback] - exception: null
03-29 01:55:29.549 ERROR [c.t.gateway.component.exception.ProducerFallback] - s:tdcm
03-29 01:55:29.552 ERROR [c.t.gateway.component.exception.ProducerFallback] - exception: null
03-29 01:55:37.508 ERROR [c.t.gateway.component.exception.ProducerFallback] - s:tdcm
03-29 01:55:37.510 ERROR [c.t.gateway.component.exception.ProducerFallback] - exception: null
03-29 01:55:39.031 ERROR [c.t.gateway.component.exception.ProducerFallback] - s:tdcm
03-29 01:55:39.033 ERROR [c.t.gateway.component.exception.ProducerFallback] - exception: null
It seems the zuul can't find the router to eureka client of tdcm.
I tried to deployed all application on computer,include eureka server,zuul,eureka client,not in docker. The same config as this article descript,it works well. I don't know why it isn't work when access the eureka client via zuul in docker deployed.
I use the host computer IP address for spring cloud appliction.
My docker version is 17.12.1-ce.
My spring cloud version is Finchley.SR1.
My Spring boot version is 2.0.3.RELEASE.
My host computer is cent-os 7.
How can I deal with the problem?

I know the problem how to dealing.Eureka client config delete the yml value of ip-address.
eureka:
instance:
ip-address: 192.168.90.183
The reason is eureka client config in the inner network of docker.It can access from zuul through inner network of docker.

Related

Spring Cloud gateway fails to establish websocket connections when server expects case sensitive headers

I have a third party webapplication having websocket connections. It is expecting Upgrade, Connection header names to be case sensitive. I am using spring cloud gateway as a reverse proxy to this webapp. All the http calls are success but for websocket requests i am getting the following error
io.netty.handler.codec.http.websocketx.WebSocketClientHandshakeException:
Invalid handshake response getStatus: 404 Not Found at
io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker13.verify(WebSocketClientHandshaker13.java:272)
~[netty-codec-http-4.1.65.Final.jar:4.1.65
WebSocketClientHandshaker is setting the upgrade and connection headers and it is in lower case. How do I override these header values ?
application.yml configuration is as below
spring:
main:
web-application-type: reactive
profiles:
active: dev
cloud:
gateway:
globalcors:
corsConfigurations:
'[/**]':
allowedOrigins: "*"
allowedMethods: "*"
allowedHeaders: "*"
httpclient:
pool:
max-idle-time: 10s
ssl:
useInsecureTrustManager: true
filter:
remove-non-proxy-headers:
headers:
- Keep-Alive
- TE
- Trailer
- Transfer-Encoding
routes:
- id : no_op
uri: no://op
predicates:
- Path=/falcon/tunneling/**
- id: reroute_ws
uri: ws://localhost:5555
predicates:
- Path=/websocket/**
- id: reroute_2
uri: http://localhost:5555
predicates:
- Path=/**

Problem with unknown ports on Spring Eureka Client registration

Well, a have tried ALL tutorials, ALL answer on Stackoverflow. But I still face the same error:
On Heroku, Eureka Clients are receiving random ports that I don't know where they come from.
And these random ports are different from Heroku Environment variable $PORT. I know that $PORT is the container Dyno port, not the host port xxxxx.herokuapp.com that the out side world can access. Again, I don't know where these ports come from!!!
The link clients in the Eureka Dashboard stay like this:
hdfb2324-8jfw-83ud-dkdf-9ej90jefj201.qwer.dyno.rt.heroku.com:inight-ws-gateway:${RANDOM PORT}
When I click, go to https://inight-ws-gateway.herokuapp.com:${RANDOM PORT}/actuator/info. I take the Timeout because the correct port is 443, Https default.
I have 3 applications, 1 Eureka Server and 2 Eureka Clients (Zuul Gateway and a trivial Rest API).
Every works ok when I run in my localhost, but when I deploy in Heroku, it's happen.
Eureka Server application.yaml:
server:
port: ${PORT}
spring:
application:
name: '#project.artifactId#' # inight-ws-discovery
version: '#project.version#'
eureka:
client:
fetch-registry: false
register-with-eureka: false
management:
endpoints:
enabled-by-default: false
web:
exposure:
include:
- health
- info
endpoint:
health:
enabled: true
info:
enabled: true
Eureka Client (Zuul gateway) application.yaml:
server:
port: ${PORT}
spring:
application:
name: '#project.artifactId#' # inight-ws-gateway
version: '#project.version#'
eureka:
instance:
hostname: ${INIGHT_EUREKA_INSTANCE_HOSTNAME} # inight-ws-gateway.herokuapp.com
client:
enabled: true
fetch-registry: true
register-with-eureka: true
service-url:
defaultZone: ${INIGHT_EUREKA_CLIENT_SERVICE_URL_DEFAULTZONE} # https://inight-ws-discovery.herokuapp.com/eureka/
healthcheck:
enabled: true
zuul:
sensitive-headers:
- Cookie
management:
endpoints:
enabled-by-default: false
web:
exposure:
include:
- health
- info
- routes
endpoint:
health:
enabled: true
info:
enabled: true
routes:
enabled: true
jwt:
config:
privateKey: ${INIGHT_JWT_CONFIG_PRIVATEKEY}
Eureka Client (Rest API) application.yaml:
server:
port: ${PORT}
spring:
application:
name: '#project.artifactId#' # inight-ws-auth
version: '#project.version#'
datasource:
hikari:
schema: inight
jdbc-url: ${INIGHT_DATASOURCE_JDBC_URL}
username: ${INIGHT_DATASOURCE_USERNAME}
password: ${INIGHT_DATASOURCE_PASSWORD}
driver-class-name: ${INIGHT_DATASOURCE_DRIVER_CLASS_NAME}
jpa:
show-sql: ${INIGHT_JPA_SHOW_SQL}
hibernate:
ddl-auto: ${INIGHT_JPA_HIBERNATE_DDL_AUTO}
eureka:
instance:
hostname: ${INIGHT_EUREKA_INSTANCE_HOSTNAME} inight-ws-auth.herokuapp.com
client:
enabled: true
service-url:
defaultZone: ${INIGHT_EUREKA_CLIENT_SERVICE_URL_DEFAULTZONE} https://inight-ws-discovery.herokuapp.com/eureka/
healthcheck:
enabled: true
management:
endpoints:
enabled-by-default: false
web:
exposure:
include:
- health
- info
endpoint:
health:
enabled: true
info:
enabled: true
jwt:
config:
privateKey: ${INIGHT_JWT_CONFIG_PRIVATEKEY}
swagger.basePackage: br.com.bz.inight.auth.controller
my fault!!!!!
I have a couple of microservices on Heroku:
Eureka Server
Zuul Gateway
Some app services
The link on Eureka Server Dashboard, doesn't matter. Whats matter is the https://GATEWAY.herokuapp.com/actuator/routes and the <port enabled="true">80</port> on https://EUREKA_SERVER.herokuapp.com/eureka/apps.
But for this happen (<port enabled="true">80</port> on app services) you MUST ,EXPLICITLY, declare in application.yaml
eureka:
instance:
non-secure-port: 80
hostname: ${EUREKA_CLIENT_INSTANCE_HOSTNAME} # herokuapp_name.herokuapp.com
If you read the documentation, you will see that the property eureka.instance.non-secure-port has the default value 80. I don't know why, but, if you don't declare it, the <port enabled="true">80</port> are not set up on microservices applications on Eureka Server.
Check the tutorial https://blog.heroku.com/managing_your_microservices_on_heroku_with_netflix_s_eureka.
Well, these are my architecture application.yaml:
coffee-eureka-server application.yaml
spring:
application:
name: '#project.artifactId#'
server:
port: ${PORT}
eureka:
instance:
hostname: ${EUREKA_CLIENT_INSTANCE_HOSTNAME} # herokuapp_name.herokuapp.com
client:
fetch-registry: false
register-with-eureka: false
service-url:
defaultZone: ${EUREKA_SERVER_URI}/eureka/ # in this case, same value of eureka.instance.hostname, but with https:// prefix, of course
coffee-zuul-gateway application.yaml
spring:
application:
name: '#project.artifactId#'
server:
port: ${PORT}
eureka:
instance:
hostname: ${EUREKA_CLIENT_INSTANCE_HOSTNAME} # herokuapp_name.herokuapp.com
client:
fetch-registry: true
register-with-eureka: true
service-url:
defaultZone: ${EUREKA_SERVER_URI}/eureka/
management:
endpoints:
enabled-by-default: true
web:
exposure:
include:
- routes
- info
- health
coffee-simple-ms application.yaml
spring:
application:
name: '#project.artifactId#'
server:
port: ${PORT}
eureka:
instance:
non-secure-port: 80 # <<<<<<<<< HERE
hostname: ${EUREKA_CLIENT_INSTANCE_HOSTNAME} # herokuapp_name.herokuapp.com
client:
fetch-registry: true
register-with-eureka: true
service-url:
defaultZone: ${EUREKA_SERVER_URI}/eureka/
When I click, go to https://inight-ws-gateway.herokuapp.com:${RANDOM PORT}/actuator/info. I take the Timeout because the correct port is
443, Https default.
When you are hosting on localhost the link would be: http://localhost:${PORT}/actuator/info
On Heroku this link is: https://inight-ws-gateway.herokuapp.com/actuator/info
The difference:
It is using http secure, https
The port number is "gone"
The hostname inight-ws-gateway.herokuapp.com is automatically translated into a ${IP_ADDRESS}:${PORT}.
You will need to adjust your source code for the https URL generation.
Your web application will run on a port different from the usual http/https port. It does not have to be 80, 8080 or 443. It can be any port. And that port is specified by Heroku through $PORT.

Why is there a delay in routing when using Zuul + Ribbon with Eureka turned off?

When Zuul routes to microservice it takes around 5 ms but on 30th second it adds 100ms + delay.
I added ribbon.eureka.ServerListRefreshInterval=60000. Now I see it refreshing its list of servers every minute but still on 30th sec the delay happens.
Can someone please tell me what's happening at 30th sec?
My Zuul configuration:
spring:
application:
name: xxxx
profiles:
active: default
cloud:
config:
failFast: true
security:
enabled: false
main:
banner-mode: 'off'
eureka:
client:
enabled: false
registerWithEureka: false
fetchRegistry: false
zuul:
host:
connect-timeout-millis: 60000 # starting the connection
socket-timeout-millis: 60000 # monitor the continuous incoming data flow
sensitiveHeaders: Cookie,Set-Cookie
ignoredServices: '*'
routes:
auth:
path: /xxx/xx/**
stripPrefix: false
#url: http://localhost:9003/
xx:
path: /xx/xx/**
stripPrefix: false
#url: http://localhost:9002/
hystrix:
command:
default:
execution:
timeout:
enabled: false
ribbon:
ReadTimeout: 60000
ConnectTimeout: 120000
eureka:
enabled: false
security:
ignored: /**
basic:
enabled: false
management:
security:
enabled: false
xx:
ribbon:
eureka:
enabled: false
ServerListRefreshInterval: 60000

Spring : Display Eureka Services as down instead of removing

I have a Eureka Server and have numerous clients. Now whenever any service gets registered it gets displayed on Eureka Page. When i kill a particular service now i want to still display it on the page with the status as down. But what is happening in my case is that speicific instance does not get displayed. Can anyone please help.
Server - Yml
spring:
application:
name: eureka
server:
port: 4544
context-path: /eureka
eureka:
server:
enableSelfPreservation: false
eviction-interval-timer-in-ms: 1000
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://localhost:4544/eureka/
instance:
hostname: localhost
homePageUrlPath: /eureka/
management:
security:
enabled: false
Client - YML
spring:
application:
name: myclient
server:
port: 3333
context-path: /myclient
eureka:
client:
registerWithEureka: true
fetchRegistry: true
healthcheck:
enabled: true
lease:
duration: 5
serviceUrl:
defaultZone: http://localhost:4544/eureka/
instance:
leaseRenewalIntervalInSeconds: 1
leaseExpirationDurationInSeconds: 2
hostname: localhost
homePageUrlPath: /myclient/

spring eureka security Batch update failure with HTTP status code 401

I study spring cloud eureka , cloud and they works finely . But after adding security in eureka service , it met some errors .
All the code and errors details is in https://github.com/keryhu/eureka-security
The eureka service application.yml
security:
user:
name: user
password: password
eureka:
client:
registerWithEureka: false
fetchRegistry: false
server:
wait-time-in-ms-when-sync-empty: 0
And The config-service application.java
#SpringBootApplication
#EnableConfigServer
#EnableDiscoveryClient
config-service application.yml
eureka:
client:
registry-fetch-interval-seconds: 5
serviceUrl:
defaultZone: http://user:password#${domain.name:localhost}:8761/eureka/
spring:
cloud:
config:
server:
git:
uri: https://github.com/spring-cloud-samples/config-repo
basedir: target/config
There is errors exported after starting the config-service:
2016-04-10 11:22:39.402 ERROR 80526 --- [get_localhost-3] c.n.e.cluster.ReplicationTaskProcessor : Batch update failure with HTTP status code 401; discarding 1 replication tasks
2016-04-10 11:22:39.402 WARN 80526 --- [get_localhost-3] c.n.eureka.util.batcher.TaskExecutors : Discarding 1 tasks of TaskBatchingWorker-target_localhost-3 due to permanent error
2016-04-10 11:23:09.411 ERROR 80526 --- [get_localhost-3] c.n.e.cluster.ReplicationTaskProcessor : Batch update failure with HTTP status code 401; discarding 1 replication tasks
2016-04-10 11:23:09.412 WARN 80526 --- [get_localhost-3] c.n.eureka.util.batcher.TaskExecutors : Discarding 1 tasks of TaskBatchingWorker-target_localhost-3 due to permanent error
2016-04-10 11:23:39.429 ERROR 80526 --- [get_localhost-3] c.n.e.cluster.ReplicationTaskProcessor : Batch update failure with HTTP status code 401; discarding 1 replication tasks
2016-04-10 11:23:39.430 WARN 80526 --- [get_localhost-3] c.n.eureka.util.batcher.TaskExecutors : Discarding 1 tasks of TaskBatchingWorker-target_localhost-3 due to permanent error
SET eureka.client.serviceUrl.defaultZone of eureka-server
http://username:password#localhost:8761/eureka/
I agree with jacky-fan answer.
These are how my working configuration looks like without username and password.
server application.yml
spring:
application:
name: eureka-service
server:
port: 8302
eureka:
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://localhost:8302/eureka/
server:
wait-time-in-ms-when-sync-empty: 0
client application.yml
eureka:
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://localhost:8302/eureka/
instance:
hostname: localhost
spring:
application:
name: my-service
server:
port: 8301

Resources