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.
Related
I have searched over stackoverflow & tried alot of solutions but with no result.
I have 2 containers one is for eureka server and another one for spring cloud gateway.
I'm running these 2 containers with docker-compose but spring-cloud-gateway didn't register to eureka server.
I'm using https. On localhost everything is working as expected but when I jumped to containers this is the problem of unregistered clients.
eureka.server.yml:
eureka:
client:
fetch-registry: false
register-with-eureka: false
instance:
secure-port-enabled: true
non-secure-port-enabled: false
server:
port: 8761
ssl:
enabled: true
key-alias: statement
key-store: classpath:statement-keystore.p12
key-store-password: secret
key-store-type: PKCS12
spring:
application:
name: netflix-eureka
spring.cloud.gateway.yml:
eureka:
instance:
nonSecurePortEnabled: false
securePortEnabled: true
securePort: 8765
prefer-ip-address: true
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: https://localhost:8761/eureka
level:
org:
springframework:
cloud:
gateway: DEBUG
reactor:
netty:
http:
client: DEBUG
server:
port: 8765
ssl:
enabled: true
key-alias: statement
key-store: classpath:statement-keystore.p12
key-store-password: secret
key-store-type: PKCS12
spring:
application:
name: api-gateway
cloud:
config:
enabled: false
gateway:
discovery:
locator:
enabled: true
httpclient:
wiretap: true
httpserver:
wiretap: true
globalcors:
corsConfigurations:
'[/**]':
allowedOrigins: "https://localhost:4200"
allowedHeaders: "*"
allowedMethods:
- GET
- POST
- PUT
- DELETE
spring.cloud.gateway.Dockerfile:
FROM openjdk:11-jre-slim
LABEL Description="SPring cloud gateway" Version="0.0.1"
ARG VERSION=0.0.1
VOLUME /tmp
ADD target/api-gateway-${VERSION}-SNAPSHOT.jar app.jar
RUN sh -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
eureka.server.Dockerfile:
FROM openjdk:11-jre-slim
LABEL Description="Eureka Server" Version="1.0"
ARG VERSION=1.0
VOLUME /tmp
ADD target/eureka-server-${VERSION}-SNAPSHOT.jar app.jar
RUN sh -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
docker-compose.yml:
version: '3.7'
services:
netflix-eureka:
image: abraham/netflix-eureka
container_name: "netflix-eureka"
ports:
- "8761:8761"
networks:
- statement-network
api-gateway:
image: abraham/api-gateway
container_name: "api-gateway"
ports:
- "8765:8765"
networks:
- statement-network
environment:
eureka.client.service-url.default-zone: https://netflix-eureka:8761/eureka
depends_on:
- netflix-eureka
links:
- netflix-eureka
networks:
abraham-network:
why is the new spring-cloud-config so complicated?
I would like to do the following: enable eureka on default and add it in some profiles (not in all).
no matter in which way I tried it, it didn't work.
I get this error Failed to bind properties under 'eureka.client.enabled' to boolean.
first way:
server:
port: 8080
eureka:
client:
enabled: false # default disabled
instance:
leaseRenewalIntervalInSeconds: 10
prefer-ip-address: false
hostname: 127.0.0.1
spring:
application:
name: app
main:
banner-mode: off
cloud:
config:
enabled: false
discovery:
enabled: true
service-id: config-server
fail-fast: true
retry:
max-attempts: 5
application:
value: app-default
---
spring:
config:
activate:
on-profile: dev
application:
value: app-dev
---
spring:
config:
activate:
on-profile: qa
import: "configserver:"
cloud:
config:
enabled: true
eureka:
client:
enabled: true # enable it in profile "qa"
serviceUrl:
defaultZone: http://127.0.0.1:8761/eureka/
application:
value: app-qa
second way:
server:
port: 8080
eureka:
client:
enabled: true # default enabled
instance:
leaseRenewalIntervalInSeconds: 10
prefer-ip-address: false
hostname: 127.0.0.1
spring:
application:
name: app
main:
banner-mode: off
cloud:
config:
enabled: false
discovery:
enabled: true
service-id: config-server
fail-fast: true
retry:
max-attempts: 5
application:
value: app-default
---
spring:
config:
activate:
on-profile: dev
eureka:
client:
enabled: false # disable in profile "dev"
application:
value: app-dev
---
spring:
config:
activate:
on-profile: qa
import: "configserver:"
cloud:
config:
enabled: true
eureka:
client:
serviceUrl:
defaultZone: http://127.0.0.1:8761/eureka/ # I also need a profile specific url
application:
value: app-qa
if I activate eureka once and never use eureka.client.enabled again, then the error with the url occurs: Failed to bind properties under 'eureka.client.serviceUrl. defaultZone' to String - but I need this profile specific url in any case!
all this has to do with the new spring-cloud-config. because after I deleted all the lines for the config-server and commented out the spring-cloud-starter-config dependency, both variants with eureka worked!
or do i have an error according to this spring-cloud-config stuff?
versions:
<spring-boot.version>2.5.2</spring-boot.version>
<spring-cloud.version>2020.0.3</spring-cloud.version>
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
My config server use natie file system works fine and the dev profile configured contextPath: /config
spring:
application:
name: dcit-config
profiles:
active: native
management:
endpoints:
web:
exposure:
include: info, health, metrics
metrics:
export:
atlas:
enabled: true
---
spring:
profiles: native
application:
name: dcit-config
cloud:
config:
server:
native:
searchLocations: classpath:/config/
server:
port: 2003
eureka:
instance:
prefer-ip-address: true
lease-renewal-interval-in-seconds: 5
lease-expiration-duration-in-seconds: 20
client:
serviceUrl:
defaultZone: http://dcit:dcit#localhost:1023/eureka
registry-fetch-interval-seconds: 10
---
spring:
profiles: dev
application:
name: dcit-config
cloud:
config:
server:
git:
uri: http://xxx/git/Arch/dcit.git
username: user
password: pass
searchPaths: dcit-config/src/main/resources/config/
clone-on-start: true
fail-fast: true
server:
port: 2002
contextPath: /config
eureka:
instance:
prefer-ip-address: true
lease-renewal-interval-in-seconds: 5
lease-expiration-duration-in-seconds: 20
client:
serviceUrl:
defaultZone: http://dc:dc#localhost:1023/eureka
registry-fetch-interval-seconds: 10
The native profile serve configs like this url: http://hostname:2003/config/app-profile.yml and my client works fine.
But if I use dev profile the url http://hostname:2002/config/app-profile.yml also works, but my client got error:
java.lang.IllegalStateException: Could not locate PropertySource and the fail fast property is set, failing
My client config:
spring:
application:
name: dcit-auth
profiles:
active: dev
cloud:
config:
fail-fast: true
discovery:
service-id: dcit-config
enabled: true
profile: ${spring.profiles.active}
label: ${spring.profiles.active}
---
spring:
profiles: dev
eureka:
instance:
prefer-ip-address: true
lease-renewal-interval-in-seconds: 5
lease-expiration-duration-in-seconds: 20
client:
serviceUrl:
defaultZone: http://dc:dc#localhost:1023/eureka
registry-fetch-interval-seconds: 10
solved by remove contextPath: /config and label configure
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/