How can I choose bootstrap.yml according to db config? - spring

I have two nacos bootstrap.yml which means two nacos with different ip, I want to load one of the bootstrap.yml according to db config.
For example, if my loadVariable value from db config is A, I want to load bootstrap-a.yml. How can I do that?
Here is my purpose step:
search data from db to decide load bootstrap-a.yml or bootstrap-b.yml
register the service to nacos according to bootstrap config file

Related

How to set preferredLocation for cosmosDB in application.properties for Springboot app?

cosmos DB has multi master set up with multiple regions. cosmos connection parameters are present in application.properties.
But my observation is, when we use CosmosRepository interface and use getById method,the call goes to any random region and not the preferred region.this is adding latency.
How to correctly setup preferred location / region in application.properties?
"preferredLocation" property seems to be not working.

Jetty Spring Boot with session replication

I am using spring boot 2.5.3 with Jetty 9.4.43.v20210629. I want to share the session across multiple nodes. In Jetty 9.4 there are lot of changes in session management. I want some reference materials for session replication (using JDBC / File system) with java configurations.
Session replication can be done using spring session with following storage options,
Hazlecast
Database
Redis
MongoDB
spring.session.store-type property should be used to decide the storage type. When multiple nodes / containers point to same storage it will share the session and no need to maintain a sticky session.
Need to add proper dependencies in pom.xml and add annotations when required (ex: #EnableJDBCHttpSession)
sample application yaml changes.
JDBC
spring:
application.name: console-bs
main.allow-bean-definition-overriding: true
profile: default
session.store-type: jdbc
session.jdbc.initialize-schema: always
jpa.database: mysql
jpa.database-platform: org.hibernate.dialect.MySQL5Dialect
datasource.url: jdbc:mysql://mysqldb:3306/user
datasource.username: user
datasource.password: user1234#
datasource.driver-class-name: com.mysql.cj.jdbc.Driver
Redis
spring:
application.name: console-bs
main.allow-bean-definition-overriding: true
profile: default
session.store-type: redis
redis.host: redis
redis.port: 6379

How to override Spring boot Consul config properties?

I use a distributed Consul config in my application, and it works well. But also i want to override some config properties, when i start an application with different Spring profile. Fo example, i define Kafka server address in the main Consul configuration:
spring:
kafka:
bootstrap-servers: some_kafka:9092
and i want to use different address when i switch to Spring profile named "local":
spring:
kafka:
bootstrap-servers: localhost:9092
How to do it? I tried using bootstrap file with suffix (bootstrap-local.yml) and Consul profile-depended setings (stored in folder "application,local/"), but it does't work for me.
In order to be able to override the properties from consul, you first need to add two properties in your consul file to enable the override. The properties are:
"spring.cloud.config.allowOverride": "true",
"spring.cloud.config.overrideSystemProperties": "false"
Please check this for more details.
Once that is done, you can now override the properties by using a JVM parameter, from your example, will be: -Dspring.kafka.bootstrap-servers=localhost:9092 or you can do the same with a bootstrap-local.yml and setting the active profile to local

Want to read gateway properties from config server

I have a spring cloud gateway in my project and I want to use config server with that.
What exactly I want to do is
enter image description here
I want to read these highlighted values from config server.
i kept these values in config server, still it reads the values from application property not from config,,,, Can som1 plz help here
when i use #value to read these values then it takes config server values...
Is it like config server only works with #value????

How to run Spring Cloud Config server in Fault Tolerance mode?

In my project we have a requirement to run two instances of spring cloud config server so if one instance goes down, other will take care the config server responsibilities.
Currently, you would need to put config server behind a load balancer. It is stateless, so that wouldn't hurt. There is an open issue to configure multiple config server url's in the client, so it could do failover there.
If you are running multiple instances of the config server, you can have them all register themselves in Eureka, and maybe do a lookup to the config server with it's application name via Eureka in all the other microservices. This way, Zuul (and Ribbon) will take care of the load balancing.
Edit:
I guess spencergibb is right. It's best to use a load balancer, for eg: ELB, if you're going to deploy on AWS.
Consider multiple spring-cloud-config-uris for high availability

Resources