org.yaml.snakeyaml.scanner.ScannerException: while scanning a simple key - yaml

server:
port: 9191
--
cloud:
gateway:
routes:
- id : USER-SERVICE
uri : lb://USER-SERVICE
predicates :
- Path=/users/**
- id: DEPARTMENT-SERVICE
uri: lb://DEPARTMENT-SERVICE
predicates:
- Path=/departments/**
--
spring:
application:
name: API-GATEWAY
eureka:
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultzone: http://localhost:8761/eureka/
instance:
hostname: localhost

Related

Failed to bind properties under 'eureka.client.enabled' to boolean

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>

parsing error in yml file for microservices

18:01:39.008 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
org.yaml.snakeyaml.scanner.ScannerException: mapping values are not allowed here
in 'reader', line 16, column 16:
uri: lb://USER-SERVICE
`
server:
port: 9190
spring:
application:
name: API-Gateway
cloud:
gateway:
routes:
- id: user-service
uri: lb://DEPT-SERVICE
predicates:
- path=/user/**
- id: dept-service
uri: lb://USER-SERVICE
predicates:
- path=/departments/**
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka
instance:
preferIpAddress: true
`
Your yaml is not valid. Check this validator as example.
Note how on line 16 and next, uri, predicates and path are not on the same column as just before.
Valid yaml is:
server:
port: 9190
spring:
application:
name: API-Gateway
cloud:
gateway:
routes:
- id: user-service
uri: lb://DEPT-SERVICE
predicates:
- path=/user/**
- id: dept-service
uri: lb://USER-SERVICE
predicates:
- path=/departments/**
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka
instance:
preferIpAddress: true

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.

Spring cloud config client Could not locate PropertySource

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

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/

Resources